Hello Guys i want to use external validation i mean javascript validation but whenever click on create i mean (add new record submit)that time my first text box is black then it give me alert but when i click on 'ok' it redirect to controller and give error not focus on same text box.
Wap Addon wrote:
Hello Guys i want to use external validation i mean javascript validation but whenever click on create i mean (add new record submit)that time my first text box is black then it give me alert but when i click on 'ok' it redirect to controller and give error not focus on same text box.
Whoa, take a step back here and slow down so that we can understand you. That's one of the longest run-on sentences I've seen in my life.
You want to use javascript validation because you are using something like a form_tag correct? Which tag are you using to start with?
Start with providing the basics of what you have, show some initial code for the piece you are having issues with.
You do not have to use javascript validation on external pieces. I have created custom validation methods for pieces like form_tag, etc.
The larger question is you mentioned a create or a submit to add a record, which tells me that you are adding it into a database. If that is the case then your validations should be performed in the model, not with javascript.
Why are you doing this in javascript when you can do this beautifully in your controller? Create the appropriate validations in your model and then in your controller check whether saving is possible. If it is, save it and redirect or whatever you want it to do. If not, catch the error and show it.
jhaagmans wrote:
Why are you doing this in javascript when you can do this beautifully in your controller? Create the appropriate validations in your model and then in your controller check whether saving is possible. If it is, save it and redirect or whatever you want it to do. If not, catch the error and show it.
ok dear but this is server side validation. i want to use client side validate.
server side take more time execution so that client side validation more fast. so that i want to use external js validation.
jhaagmans wrote: > Why are you doing this in javascript when you can do this beautifully > in your controller? Create the appropriate validations in your model > and then in your controller check whether saving is possible. If it > is, save it and redirect or whatever you want it to do. If not, catch > the error and show it.
ok dear but this is server side validation. i want to use client side validate.
server side take more time execution so that client side validation more fast. so that i want to use external js validation.
I hope you are also doing server side validation. This is better done from the form's onsubmit, and don't forget to return the value of your validation function (don't just call it as you are doing now)
Fred
jhaagmans wrote:
Why are you doing this in javascript when you can do this beautifully in your controller? Create the appropriate validations in your model and then in your controller check whether saving is possible. If it is, save it and redirect or whatever you want it to do. If not, catch the error and show it.
ok but as per my above validation code is not possible ?
Don't think like this - as other posters have pointed out, you're going to have to do server-side validation anyways. Worrying about the execution time of something this small is exceptionally premature optimization.
In your example, the JS validation may work, but you're still going to have to validate server-side, as some users may have JS turned off.
--Matt Jones