Hi Everyone,

I have a rather complicated form for a search engine that has one text
input field and several drop down fields. Essentially, I need to be
able to track changes in the form fields as well as access them via
JavaScript to change the values programmatically in certain
situations. Obviously, tracking changes is easy but changing the
values programmatically is a little more complicated when the drop
down fields are generated dynamically and post to the same variable as
an array.

To get a better idea, it might look something like this:

<input type="text" name="q" />
<select name="t[]" id="filter_1">
  <option value="1">Foo</option>
  <option value="2">Bar</option>
</select>
<select name="t[]" id="filter_2">
  <option value="3">Baz</option>
  <option value="4">Fooz</option>
</select>

The drop down field values map to a taxonomy in the database so there
isn't much to distinguish any of the filters except for the id.

When I first built this in JavaScript, I used Harald Kirschner's
Observer class (part of the Autocompleter) and adapted it to work with
more form field types and then when the Form class was instantiated,
it would find all the fields and create a new observable for them so
that I could change the values of any form fields through the form
object. This works okay for the most part except there are some weird
recursion problems that pop up sometimes in Internet Explorer and I
could not for the life of me understand what was going on but somehow
managed to get working (for now at least).

So, what I have is several form fields that I needed to access without
knowing much about them, a Form object that tracks all of its fields
internally by wrapping them in an observable object, and another class
that models the actual search query to validate the form before
submission.

I don't think this solution is very efficient and I was wondering if
anyone else has any thoughts on a better way to handle this situation?
I can post the code to MooShell but it will take me a while to get
everything in there and I'm not sure how helpful it will be... maybe
thinking about the problem in the abstract is better?

Reply via email to