[html-formfu] dynamically filter a Select list

Byron Young Byron.Young at riverbed.com
Mon Sep 14 21:33:39 GMT 2009


Ascii King wrote on 2009-09-14:
> Byron Young wrote:
>> Ascii King wrote on 2009-09-14:
>> 
>>> I want to dynamically filter the amount of data returned when
>>> populating a Select field.  The select field I am using has too much
>>> data and causes the form to load very slowly.  I have several of these
>>> select boxes, that pull down different data. I need to be able to
>>> filter what data gets into the boxes based on choices the user makes.
>>> 
>>> 
>> 
>> I don't think there is a built-in way to do this in HTML::FF
> (please correct me if I'm wrong!), but for things like this I just
> use FormFu to render the empty input fields in the form, and then I
> add some javascript to the page to asynchronously load the Select
> list data as the user types into the filter text box (or conversely
> you can have all the data loaded with FormFu and just filter it as
> the user types into the filter field).  FormFu still handles the
> rendering, validation, etc, but my javascript handles the list
> contents and filtering.
>> 
>> HTH,
>> Byron
>> 
>> 
> That solution provides the functionality I want, but still leaves me
> with the 'too much data' problem. Thanks, though. The solution I am
> considering using is to have the clients fill out a pre-form taht I use
> to filter the data. That is a clunky solution, though. I was hoping
> there was a proper way to do it.
> 

If you go the route of dynamic-population via AJAX you can avoid the 'too much data' problem.  Initially don't put any data in the Select list, but once the user starts typing in the filter box do an AJAX query to pull only the filtered values into the Select list.  The form should load quickly initially since there isn't any data to load, and the filter queries should be pretty quick (depending on your data set and the filter being used) because the data will always be filtered.

Alternatively, you could do a multi-step approach: show a paginated list of doctor's names, with links to each letter of the alphabet to jump to last name at the top.  The user browses through the list and selects the doctor they want.  Then they are taken to your form page with the doctor's name put into a hidden form field, and they can fill out the rest of the data there.

Byron




More information about the HTML-FormFu mailing list