Skip to content

Instantly share code, notes, and snippets.

@msrivastav13
Created March 12, 2014 19:36
Show Gist options
  • Save msrivastav13/9514618 to your computer and use it in GitHub Desktop.
Save msrivastav13/9514618 to your computer and use it in GitHub Desktop.
$(function() {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MobileHomeCtrl.fetchallUsers}',
function(result, event){
if (event.status) {
var availableTags = [];
$.each(result,function(){
var obj = new Object();
//match the passed label and returned value to populate the label and value
obj.label = this['FirstName']+' '+this['LastName'];
obj.value= this['id'];
availableTags.push(obj);
});
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#popid" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).autocomplete( "instance" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
//return the dataa
response( availableTags);
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
var hidefield=split( $( "#hiddenField" ).val());
// remove the current input
terms.pop();
hidefield.pop();
// add the selected item
terms.push( ui.item.label );
hidefield.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push( "" );
hidefield.push( "" );
this.value = terms.join( ", " );
$('#hiddenField').val(hidefield.join(", "));
return false;
}
});
} else if (event.type === 'exception') {
} else {
}
},
{escape: true}
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment