I have a function that compares two fields.
$ Val (1) "Validator.addMethod" ("# field1"). Val () & gt; $ ('# field2'). Val ()}, "test");
Form dynamic And therefore this form is valid using the each
:
$ ('.validateclass'). (Function () {$ (this). Rule (' ('Validateclass2'). (Function () {$ (this). Rule ('Add', {Required}}, 'Add', {ValidationCertificate: Truth, Message: {Validation: "Test"}})}) : True, Message: {Required: "This field is required"}}}});. $ ('# MyForm') Valid ();
Now my problem is message Test As soon as the page gets loaded, it should be visible only after comparing the field. I know this line is due to the
$ ('# formSaveComponent'). Valid ();
But I think the page wants to show the message when it is loaded. Is there any way i can get it using a valid jQuery plugin?
quote OP:
" Now my problem is that the page is loaded Message test is displayed as D. This field should be shown only after comparing it. "
You have written your custom method such that the field is required
... so You are getting an error message right away and while the area is still empty.
Unless these fields are required
, you have to add the this.optional (element) ]
for your custom method as ...
$. Validator.addMethod ("validatormethod", function (value, element) {return.optional (element) $ $ ('# 1 field'). Val () & gt; $ ('# field2'). Val ()}, "test");
Now the custom method will not run until entered in any relevant field
Comparing with txtFirstName
to & gt;
comparison operator ... how exactly can a name be "greater than the other"? Edit
is broken because ...
-
You
id
F While targeting the field, your field has only onename
and noid
is notname
to target them byChange $ ('# fieldname')
to$ ('[name = "fieldname"]')
. -
You are comparing two strings with a comparison operator, which will always fail because the number of strings is not. You can compare the string to convert it to an integer Need to ...
parseInt ($ ('[name =' fieldname ']'). Val ())
Demo:
Comments
Post a Comment