Hi,
I'm using jQuery autocomplete in multiple way, so many elements (users in my case) can be inserted in the input field.
Im using two fields: one where the user writes the names and another one that is hidden where the id of the users are written in this way: |34|78|43|...
This is my code:
jQuery
(document).ready(function() {
jQuery
("#campo")
.autocomplete('autocomplete', jQuery.extend({}, {
dataType
: 'json',
parse
: function(data) {
var parsed = [];
for (key in data) {
parsed
[parsed.length] = { data: [ data[key], key ], value: data[key], result: data[key] };
}
return parsed;
}
}, {multiple:true}))
.result(function(event, data) { alert(data[1]); alert($("#campo_autocomplete").val()); $("#campo_autocomplete").val($("#campo_autocomplete").val()+"|"+data[1]); });
});
} );
When the form is submitted, I will have use a php function to create an array from the string id|id|id...
Do you think it is a good approach?
Regards
Javi