views:

211

answers:

2

Is there a way to generate both a Javascript function call and an Ajax call in the same observe_form tag? For example, something like this:

<%= observe_form 'user_filter_form', :url => { :action => :process }, :function => :fix_fields %>

Thanks!!

A: 

Your best bet here is to dig into the actual JavaScript instead of relying on the helpers. The helpers can only get you so far. What you want is something along these lines:

<script type="text/javascript">
  new Form.EventObserver('user_filter_form', function(element, value){
    fix_fields();
    new Ajax.Request("/YOUR_CONTROLLER/process");
  }
</script>

However, if you really want to rely on the Rails helpers you can do something like:

<%= observe_form 'user_filter_form', :function => "fix_fields(); #{remote_function(:url => { :action => :process })}" %>
Peter Wagenet
A: 

Use :before or :after options instead of :function, depending on whether you want your function called before of after the Ajax request.

See documentation of link_to_remote helper for common options that can be passed to all the Ajax helpers like observe_form

showaltb