Skip to content

Instantly share code, notes, and snippets.

@msrivastav13
Created June 29, 2013 16:41
Show Gist options
  • Save msrivastav13/5891792 to your computer and use it in GitHub Desktop.
Save msrivastav13/5891792 to your computer and use it in GitHub Desktop.
Jquery Autocomplete with Remote Action
<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>
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