Ajaxy select boxes and existing records

I’ve just made my first form using select boxes that update each other
via observe_field. It works really well for the creation of record and
it’s making the form a whole lot nicer to use.

The problem is editing records, the first select box is not part of the
model but is used to populate the second select, which is a required
attribute of the model. When the edit form is displayed, the second box
is blank (as the first needs to be selected) and so you have to manually
change it before you edit anything else and submit the form.

I’m hoping there’s some clever trick I haven’t even thought of that
could make this work. Ideally, when the form is displayed, id like it to
get set the first select box based on the contents of the second, and
then set the second to the models attribute.

I’m not sure if I’m explaining this very well so please don’t hestitate
to shout for more info. I’d be very grateful to know how to get around
this.

Thanks

Matt

Matt H. wrote:

I’m hoping there’s some clever trick I haven’t even thought of that
could make this work. Ideally, when the form is displayed, id like it to
get set the first select box based on the contents of the second, and
then set the second to the models attribute.

I’m not sure if I’m explaining this very well so please don’t hestitate
to shout for more info. I’d be very grateful to know how to get around this.

I’ve managed to solve this, just in case anyone else comes looking for
this solution:

I changed the edit form so that it populates the first select box
normally and sets it up to update the second box, but made it set
:selected on the right entry.

Then I populated the second box initially with only the relevant entries
and set :selected on the correct one.

Now, the form can be submitted without manually selecting the right
entries, but if the user wishes to change them, ajax will still work.

I know the explanation of the problem or the solution isn’t very good,
but I hope this might help someone in the same situation.

Matt