I am using rails3-jquery-autocomplete gem to fetch the autocomplete items from the database along with some extra data that I need to pre-fill a form.
autocomplete :link, :name, :extra_data => [:url, :is_full_screen, :is_auto_trigger, :is_ad, :is_ecommerce]
Everything other than the url are boolean flags (user preferences) that are used to check/uncheck checkboxes and select radio buttons in a form. Even though the gem updates a text field, but it does not automatically update checkboxes and radio buttons. I have already specified :update_elements in form view:
<%= f.autocomplete_field :name, autocomplete_link_path, :update_elements => {:url => '#link_url', :is_auto_trigger => '#link_is_auto_trigger'}
How do I do this? I tried exploring the railsAutocomplete.select javascript event that gets fired when the option is selected, to execute custom js to select checkboxes and radio buttons, but how do I get the data (from sql query) in that event listener? Is their a simpler way to do this?
I solved this by executing custom javascript to update checkbox/radio on selecting one of the autocomplete options. A javascript event named
railsAutocomplete.selectis fired on the input field when a value is selected from the autocomplete drop down. The data.item has all the data that you fetched from the databases (including the extra data):