简体   繁体   中英

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

I need to validate form on client-side and I was wondering 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.

我认为客户端验证不是一个好主意,因为如果在客户端进行验证,则意味着客户端可以轻松绕过它。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM