There is combobox with autocomplete enabled. How to pass JSON data as source for this combobox?
Upd. I\'ve found partial answer here - it allows me
Here is the working example - http://jsfiddle.net/and7ey/TFerw/3/
Remote end should return some values (most popular) in case when empty term
is requested - it happens when user presses combobox button.
Example taken from the link you added in your question :
$( "#birds" ).autocomplete({
source: "search.php", // remote site
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
I just used next construction: 1. In combobox.js I put code from example that appears on https://jqueryui.com/autocomplete/#combobox and had changed _create & _createAutocomplete functions as follows:
_create: function() {
this.wrapper = $( "<span>" )
.addClass( "custom-combobox" )
.insertAfter( this.element );
var autocompleteSetup = this.options.autocompleteSetup;
this.element.hide();
this._createAutocomplete( autocompleteSetup );
this._createShowAllButton();
}
_createAutocomplete: function(setupObject) {
...
this.input = $( "<input>" )
.appendTo( this.wrapper )
.val( value )
.attr( "title", "" )
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
.autocomplete(setupObject)...
From page code where I'm creating the combo I am calling the create code as follows:
var options = { autocompleteSetup : { delay: 100, minLength: 2, source: "http://your/data/hook/url" } }; $( "#subzero" ).combobox(options);