Observe_form without ajax?

This betrays my lack of javascript knowledge, but is it possible to
watch a whole form for changes and activate some javascript when those
changes occur without any remote request?

That is, I want to do exactly what observe_form does, but without the
ajax call actually happening. I realize I could use the form_tag
:onchange parameter, but that seems to be incapable of doing things like
updating a DOM element style.

Currently I just put my javascript in :complete and have the ajax render
:nothing => true, but that’s a hack and uses unnecessary bandwidth.


Although in danger of answering my own question, I just discovered how
to work prototype’s Form.Observer. It appears to do the trick, although
it means I have to encapsulate my javascript in a separate function in
order to use the callback feature.

Sorry to trouble you all.


If you are running EdgeRails or the new Rails 1.1.0 RC1 release
candidate then you can do this in your view:

<%= observe_form ‘form_id’, :frequency => 2, :function => “alert
(‘Form changed’)” %>

The :function option can be any javascript that you want to execute.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs