G
Generale Cluster
Hello, I have a jquery ui autocomplete widget in a form and I'd like to
preselect its value from a database.
My autocomplete works in the following way: the id is a number, the
label and the value are the same and are a concatenation of id + " - " +
description.
When a value from the autocomplete is selected, a hidden field's value
is set to the value of id.
Then, the hidden field value is saved to the db when the form is
submitted. When the user comes back on the page for editing, I need to
reload the value from the db: I set the hidden field value again and
then I would like to precompile the value of the autocomplete widget
with the concatenation of id + " - " + description taken form the db.
I think I should trigger the event of selecting a row in the
autocomplete, but I don't know how to do. Do you have any ideas? Here is
the code of the autocomplete:
$('#codice_contratto').autocomplete({
source: 'do_contratto.php',
select: function(event, ui) {
$('#id_contratto').val(ui.item.id);
}
});
then I'm able to open the autocomplete with
$('#codice_contratto').autocomplete('search',$('#id_contratto').val());
I'm missing how I can iterate the list of found options and select the
appropriate one according to the value of the "id" property.
Thank you
Regards
preselect its value from a database.
My autocomplete works in the following way: the id is a number, the
label and the value are the same and are a concatenation of id + " - " +
description.
When a value from the autocomplete is selected, a hidden field's value
is set to the value of id.
Then, the hidden field value is saved to the db when the form is
submitted. When the user comes back on the page for editing, I need to
reload the value from the db: I set the hidden field value again and
then I would like to precompile the value of the autocomplete widget
with the concatenation of id + " - " + description taken form the db.
I think I should trigger the event of selecting a row in the
autocomplete, but I don't know how to do. Do you have any ideas? Here is
the code of the autocomplete:
$('#codice_contratto').autocomplete({
source: 'do_contratto.php',
select: function(event, ui) {
$('#id_contratto').val(ui.item.id);
}
});
then I'm able to open the autocomplete with
$('#codice_contratto').autocomplete('search',$('#id_contratto').val());
I'm missing how I can iterate the list of found options and select the
appropriate one according to the value of the "id" property.
Thank you
Regards