Hi I have an text field that implements jquery autocomplete. Everything is working great.
What I need now is in the "Select" event I want to be able to read the item json object. Right now the only two properties available are "label" and "value".
Here is the code:
$( "#txtfatherslast" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: '@Url.Content("~/Home/SearchVisitor")/',
type: 'POST',
contentType: 'application/json',
dataType: "json",
data: JSON.stringify(
{
fathersLast: "",
mothersLast: "",
firstName: ""
}),
success: function( data ) {
response( $.map( data.results, function( item ) {
return {
label: item.FathersLast + " " + item.MothersLast + ", " + item.FirstName + " (" + item.OrganizationName + ")",
value: item.FathersLast
}
}));
}
});
},
minLength: 3,
select: function( event, ui ) {
alert(ui.item.label); // here I would like to get item.FathersLast etc...
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
So the Select event:
....
minLength: 3,
select: function( event, ui ) {
// here i want to be able to read item.FathersLast or item.MothersLast.. is that possible?
alert(ui.item.label);
},
...
Any clue on how can I get the json object properties in the Selected event?
Thanks