Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  91] [ 4]  / answers: 1 / hits: 96282  / 10 Years ago, thu, september 25, 2014, 12:00:00

I have created jQuery UI autocomplete which is working very good. But my requirement is that what I display as list should also select same in text box. But it is not selecting
For example list like XXX (XYZ) but when I select it only select XXX not XXX (XYZ)
what I am missing !!



function getDeptStations() {
$(#txDestination).autocomplete({
source: function (request, response) {
var term = request.term;
var Query = ;
if (lang === en)
Query = City_Name_EN;
else if (lang === fr)
Query = City_Name_FR;
if (lang === de)
Query = City_Name_DE;
if (lang === ar)
Query = City_Name_AR;
var requestUri = /_api/lists/getbytitle('Stations')/items?$select=City_Code, + Query + &$filter=startswith( + Query + ,' + term + ');
$.ajax({
url: requestUri,
type: GET,
async: false,
headers: {
ACCEPT: application/json;odata=verbose
}
}).done(function (data) {
if (data.d.results) {
response($.map(eval(data.d.results), function (item) {
return {
label: item[Query] + ( + item.City_Code + ),
value: item[Query],
id: item[Query]
}
}));
}
else {

}
});
},
response: function (event, ui) {
if (!ui.content.length) {
var noResult = { value: , label: No cities matching your request };
ui.content.push(noResult);
}
},
select: function (event, ui) {
$(#txDestination).val(ui.item.label);
cityID = ui.item.id;
},
minLength: 1
});
}

More From » jquery

 Answers
9

Almost there, just return a false from select event.



select: function (event, ui) {
$(#txDestination).val(ui.item.label);
cityID = ui.item.id;
return false;
},


or Simply



select: function (event, ui) {        
alert(ui.item.id);
return false;
},


This will guide jquery autocomplete to know that select has set a value.



Update: This is not in the documentation, I figured out by digging into source code, took me some time. But indeed it deserves to be in the doc or in options.


[#69339] Tuesday, September 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaidyn

Total Points: 633
Total Questions: 102
Total Answers: 100

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;