Validating the Remote Form in Rails

Posted on November 17, 2008, under Rails.

I was trying to validate a form which has a Ajax Request i.e. the form has form_remote_tag

<%= form_remote_tag(:html =>{:autocomplete => "off"}, :loading => "Element.show('search_spinner')",:complete => "Element.hide('search_spinner')", :url =>{ :controller => "/order_domain", :action => "lookup" }) -%>

After googling I found the :before filter can be used with Form Remote Tag

<%= form_remote_tag(:html =>{:autocomplete => "off"}, :loading => "Element.show('search_spinner')",:complete => "Element.hide('search_spinner')", :before=> "if (!check_domain_name()) {return false;}", :url =>{ :controller => "/order_domain", :action => "lookup" }) -%>

and now the validation is true then the Ajax request would be placed otherwise it return false.

Also you may be interested to read more here

Leave a Comment

You must be logged in to post a comment.