> I am using jquery.autocomplete in a search for schools. I have
> optional fields (referenced as extraParams) which allow the user to
> narrow the search to a specific state and city.
>
> This part works fine. If the user selects a state and city and then
> initiates the search be entering a value into the autocomplete field,
> then everything works well.
>
> My issue is that I need to execute the search and return results to
> the autocomplete field when the user selects a state (and nothing has
> been entered into the autocomplete field).
>
> Obviously, I have an onChange event in the State field which can
> trigger the search event, but I don't know how to manually cause the
> search to occur (passing a wildcard for the value of q).
>
> Any suggestions would be GREATLY appreciated.
this question comes up periodically here. look in the archive for a thread
called "Autocomplete plugin for multiple form fields from a JSON source".
the kernel is to set minChars to 0 and then when you send two 'click' events
to the field when you want the suggestions to pop open, e.g. inside your
.result() event handler for state input, put:
$("#city").setOptions({minChars: 0}).trigger('click').trigger('click');
or it could go in an onfocus handler on the city field, as you wish.
No comments:
Post a Comment