Created
June 29, 2013 16:41
-
-
Save msrivastav13/5891792 to your computer and use it in GitHub Desktop.
Jquery Autocomplete with Remote Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="MyJSController"> | |
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> | |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> | |
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.MyJSController.getAccount}', | |
function(result, event){ | |
if (event.status) { | |
var availableTags = []; | |
availableTags=result; | |
// alert('availableTags'+availableTags); | |
$( "#tags" ).autocomplete({ | |
source: availableTags | |
}); | |
} else if (event.type === 'exception') { | |
} else { | |
} | |
}, | |
{escape: true} | |
); | |
}); | |
</script> | |
<div class="ui-widget"> | |
<label for="tags">Tags: </label> | |
<input id="tags" /> | |
</div> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global with sharing class MyJSController { | |
public String accountName { get; set; } | |
public static Account account { get; set; } | |
public MyJSController() { } // empty constructor | |
@RemoteAction | |
global static List<String> getAccount() { | |
List<String> accname=new List<String>(); | |
List<Account> lstaccount = [SELECT id, name, phone, type, numberofemployees FROM | |
Account]; | |
for( Account acc:lstaccount){ | |
accname.add(acc.name); | |
} | |
return accname; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment