开发者

live validation with ajax & rails 3

I am using ruby on rails 3. with UJS and jquery I am trying to generate an AJAX form. As we know that the form remains as a normal form even though it is AJAX only remote-data=>true gets added.

The form is checked on the fly for remote-data=>true and then it performs and ajax request.

Now How do I perform live vali开发者_运维百科dation after the submit button is clicked.

What I want is .-- When the submit button is clicked all the valications should be performed on client side and then if everything is perfect I want the form to be submitted. If there are any eroors the form should not be submitted.

An idea ?


I tried doing this so every form which is a remote form check if the fields are valid. If the fields are valid the return true from ajax:before send else return false.

$('.remote_form').live('ajax:beforeSend', function(event, elements){

if(validate_fields(this))
 {
        return true;
 }
 else
     return false;
      });

Note : Validate_fields is user-defined function to check for validations.


Check out this two Posts:

the validate plugin is out of the box "onSubmit" responsive.

With the tutorial should should come along to implement ajax validation as well. http://docs.jquery.com/Plugins/Validation http://sleekd.com/tutorials/jquery-validation-in-ruby-on-rails/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜