Skip to content

Instantly share code, notes, and snippets.

@jagjeetgit
Created February 23, 2018 02:03
Show Gist options
  • Save jagjeetgit/785ffb7ad207aa8cd3a5538cafa7d535 to your computer and use it in GitHub Desktop.
Save jagjeetgit/785ffb7ad207aa8cd3a5538cafa7d535 to your computer and use it in GitHub Desktop.
Auto Complete Widget in AEM Forms
//Refer to the detailed working of autocomplete widget, if you are lost with the below javascript code.
//addressLookup is the name of widget
//Creating a widget extending the textfield.
$.widget( "xfaWidget.addressLookup", $.xfaWidget.textField, {
_widgetName:"addressLookup",
//overriding render function of text field.
render : function() {
var $control = $.xfaWidget.defaultWidget.prototype.render.apply(this, arguments);
if($control){
$control.autocomplete({
source: function( request, response ) {
$.ajax({
url: "", //***add the url to get the list (probably json)
response( $.map( data, function( item ) {
return {
label: "",//***label of item
value: "",//***value of item
id: ""//***id of item
}
}));
}
});
},
//number of letters after which you want to send first autocomplete call
minLength: 4,
select: function (event, ui) {
//***update the fields you want to update on select
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
}
return $control;
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment