I solved it in dirty way :)
Actually I'm using local data, so i had trouble with that one first, here is the solution, who wants to use local data with ID's, and autopopulate default value based on ID in query string

- var data = [ // array of local data
{text:'Cat 1', aid:'1'}, - {text:'Cat 2', aid:'2'}
- // ... etc
];
- $("input#cat").autocomplete(data, {
matchContains: true,
minChars: 0,
max: 120,
formatItem: function(item) {
return item.text; // return 'Cat 1' or 'Cat 2' inside autocomplete
}
}).result(function(item) {
$("#category").val(item.aid); // add ID to the hidden field which goes to DB actually
});
Now You will need your programming language:
- if querystring <> '' // this line is just example, not really any programming language
$('#cat').val('Cat 1'); // also you will need to retrieve CAT name with your program. language
$('#category').val('1'); // also you will need to retrieve CAT ID with your program. language
And thats it :)
On focus of autocomplete field, cat name doesn't disappear , id is added... etc
Hope will help someone
