Is there any plugin which will help me validate model on client-side?
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.
精彩评论