how to precompile a jquery ui autocomplete widget?

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-05-31T16:00:25Z Indexed on 2010/05/31 16:02 UTC
Read the original article Hit count: 384

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, tha 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 idden 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? Thank you Here is the code of the autocomplete:

$('#codice_contratto').autocomplete({
    source: 'do_contratto.php',
    select: function(event, ui) {
                $('#id_contratto').val(ui.item.id);
            }
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui