Reputation: 19268
I have a autocomplete on the page using jQuery UI and here is the JSON:
[ {"label":"test1", "value":"1"},
{"label":"testtest", "value":"6"},
{"label":"test2", "value":"8"} ]
The default action of autocomplete will grab the value of the item and place into the input box. Is there a way I can stop it? Instead have two separate actions: one inject to a hidden box (with value) and the other to the input box with (label).
$.getJSON('index.php?controller=account&action=getusers', function(data) {
tempJson = data;
$(".auto-search").autocomplete({
minLength: 2,
dataType: 'json',
source: tempJson,
select: function (event,ui) {
$('input[name="user-id"]').val(ui.item.value);
}
});
});
Upvotes: 3
Views: 11934
Reputation: 5760
This is the actual HTML created by the combobox script:
<p class="dlgline">Select activity:<br>
<select id="biActivity_id" style="display: none;"><option value="1">2015/12/23 14:26 for 1 hour, 3 minutes, Demo</option></select>
<span class="custom-combobox"><input title="" class="custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autocomplete-input" autocomplete="off"><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only custom-combobox-toggle ui-corner-right" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>
</p>
<p class="dlgline">Select project:<br>
<select id="biProj_id" style="display: none;"><option value="1">Productive Non Contract</option><option value="2">Non Project Sales</option><option value="3">Waiting Time</option><option value="5">BEL SEM gateway</option><option value="6">Electronic Timesheets</option><option value="7">Fieldbus Speed Module</option><option value="8">Power Management Systems Design</option></select><span class="custom-combobox"><input title="" class="custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autocomplete-input" autocomplete="off"><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only custom-combobox-toggle ui-corner-right" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>
</p>
Upvotes: 0
Reputation: 100175
Do you mean something like:
........
select: function (event,ui){
$('input[name="user-id"]').val(ui.item.label);
$('input[name="your-hidden-field"]').val(ui.item.value);
return false;
}
Upvotes: 8