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. -Payton
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. -Payton Payton Swick wrote:> 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. > > -Payton > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
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.
-Jonathan
On Mar 21, 2006, at 6:11 PM, Payton Swick wrote:
> 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.
>
> -Payton
>
> Payton Swick wrote:
>> 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.
>> -Payton
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails