I am using Jquery Ui1.10.3 + jquery 1.10.2
<div class="ui-widget">
<label for="tags">From</label>
<input type="text" id="tags">
<input type="hidden" id="tags-id">
</div>
//Not Working
<script type="text/javascript">
var states = [{"id":134,"name":"Bangalore"},{"id":1198,"name":"Pune"},{"id":1199,"name":"Jaipur"},{"id":1,"name":"Pune"},{"id":11,"name":"KB cross"},{"id":111,"name":"silk board"},{"id":2,"name":"xvb"},{"id":22,"name":"As peta"},{"id":222,"name":"Mangalore"},{"id":3,"name":"Mysore"},{"id":33,"name":"Panjab"},{"id":333,"name":"Delhi"},{"id":4,"name":"Mumbai"},{"id":44,"name":"Chandigarh"},{"id":444,"name":"Ajmer"},{"id":5,"name":"Odisa"},{"id":55,"name":"New delhi"},{"id":555,"name":"agra"},{"id":6,"name":"Jammu"}];
$( "#tags" ).autocomplete({
maxLength: 5,
source: states,
// Focus - if you mouse over any item the input field replace by that value
focus: function( event, ui ) {
$( "#tags" ).val( ui.item.name );
return false;
},
// Select - If you select any item it'll give the values (ID) and label
select: function( event, ui ) {
$( "#tags" ).val( ui.item.name ); // Label display
$( "#tags-id" ).val( ui.item.id ); // Assign ID with respect city.
// TODO - As of now no required
// $( "#project-description" ).html( ui.item.desc );
// $( "#project-icon" ).attr( "src", "images/" + ui.item.icon );
return false;
}
})
// Build the List Items
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append( "<a>" + item.name + "</a>" )
.appendTo( ul );
};
</script>
I want code should work with name instead of label any idea how can i resolve this problem..
i am following this link "http://jqueryui.com/autocomplete/#custom-data"
- if i will change name from label code will work fine.