Using observe_form

Posted by Mike Mangino on Dec 20, 2006

The documentation for observer_form is pretty sparse. It says:

Like observe_field, but operates on an entire form identified by the DOM ID form_id. options are the same as observe_field, except the default value of the :with option evaluates to the serialized (request string) value of the form.

It sounds to me like I should be able to do:

observe_form(  'search_form',
                      :frequency  =>  1,
                      :url        =>  { :action =>  :search })

And have that work. Of course, if you do that, it doesn't submit any form values. With observe_field, you either need to specify :with=>'value' or use the :update flag. I've played around with a ton of options and never got anything to actually submit a full and complete form.

The solution is incredibly simple:

observe_form(  'search_form',
                      :frequency  =>  1,
                      :url        =>  { :action =>  :search },
                  :submit     =>  'search_form')

That tells it to submit the form when a value is changed. That's all it took. I'm really glad to have found it, and can't believe it took so long.