The escape character is \\ and not a single . The following code worked
$("#contact\\.emailAdressTxt")
Question
I am trying to add jquery validations to an exisitng spring form.
The issue is in spring form if you have following
<form:input size="60" path="contact.emailAddressTxt"/>
The HTML generated is
<input id="contact.emailAddressTxt" type="text" size="60" value="" name="contact.emailAddressTxt">
If you observe the value for name and id gets genearated. In Jquery validate plugin when I try to set rules using the generated names, it fails to load. In Jquery I cannot use contact.emailAddressTxt
So how do I validate such input fields using jquery validate plugin?
Solution 2
The escape character is \\ and not a single . The following code worked
$("#contact\\.emailAdressTxt")
OTHER TIPS
In jquery a dot is a special character so you need to escape it.
Try: $("#contact\.emailAdressTxt")
Else you can also use a class for each validation type. Like this you would not need to bind each input explicitly.
I'm not sure if you can control the way ids are generated in spring. In Jsf I've used underscores and this was easy with jquery. Probably you can do something similar.
You can set the I'd, even in spring:input tag
Try this:
<form:input id="contactEmail" name="contactEmail" type="email" label="E-mail" size="60" path="contactEmail"/>
In Jquery validate plugin when I try to set rules using the generated names, it fails to load.
You would simply surround the name
with quotes.
$("#myform").validate({
rules: {
"contact.emailAddressTxt": {
required: true
}
}
});