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
Validation across Models
I was looking for a way, where I can validate a field across models. For instance, I wanted to validate a email or phone number, where I can define it in a place and use it across the models/controllers. I searched and found the following link.
http://www.marklunds.com/articles/one/312