开发者

Is there any plugin which will help me validate model on client-side?

开发者 https://www.devze.com 2022-12-31 02:40 出处:网络
I need to validate form on client-side and I was wonder开发者_C百科ing if there is a rails plugin which will help me in this task? Maybe it will build javascript needed to validate certain model from

I need to validate form on client-side and I was wonder开发者_C百科ing if there is a rails plugin which will help me in this task? Maybe it will build javascript needed to validate certain model from ActiveRecord validations?


validation from client side you have 2 options

1 - using pure javascripts (but you will not be able to validate somethings like 'uniqueness' which requires database support)

2 - Using Ajax do your validations from the back end You may use something like Ajax.Updater to show green color tick or red cross upon validations

And If you want to use ActiveRecord validations I would recommend 'livevalidation' plugin http://github.com/porras/livevalidation.git

hope this helps

cheers sameera


No you have to write your own javascript to validate the form.

You can apply some validation such as "field can't be blank" or "minimum characters required should be 6" or "value should be valid integer" on client side but how do you validate "Username should be unique" etc on client side?

Also You should validate your model on Serverside although you are applying Client Side Validations because User may Submit the Form by disabling javascript of Browser.


I don't think that the client side validation is a good idea, because if there is on clients side means that the client can easily bypass it.


Have a look at this gem: https://github.com/bcardarella/client_side_validations . It defines client side validations from your model validations, reducing the risk that your frontend and backend validations get out of sync over time.

0

精彩评论

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

关注公众号