Изучил автозаполнение пользовательского интерфейса Jquery (v1.8.5) и понял, что отсутствует серьезная документация по отправке дополнительных параметров и съемке дополнительных данных для автозаполнения других полей. То, что у меня работает, но если серьезно, похоже на такой взлом ... Есть мысли о том, как это улучшить?
<script type="text/javascript">
var optofirst = {
width: 375,
// doing "$(this)" here fails
source: function( request, response ) {
// grab the calling element
// "$(this)" here works but ya gotta dig to get to the ID
var cat = $(this);
var callid = cat[0].element.context.id; //digging away
$.ajax({
// doing "$(this)" here fails
url: "automagic.php",
dataType: "json",
data: {
term : request.term,
//send its ID to the php script
grab : callid,
},
success: function( data ) {
response( $.map( data, function( item ) {
return {
// start assigning item handles to the response
label: item.first,
value: item.first,
last: item.last,
}
}));
}
});
},
select: function( event, ui ) {
console.log( ui.item ?
"Selected: " + ui.item.last :
"Nothing selected, input was " + this.value);
// make #lname have the value last name
// the "item" in this case appears to get its info from the handles assign in "success:"
$("#flyover #lname").attr("value",ui.item.last);
},
minLength: 2,
};
$("#flyover #fname").autocomplete(optofirst);
</script>