Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>faced similar issue with it,</p> <p>in fact what you'll notice is that validator is undefined at line 124, i.e. there is no validator instance associated with the form</p> <p>if you check the validate method you see that if validator is undefined it will create a new one </p> <pre><code>var validator = $.data(this[0], 'validator'); if ( validator ) { return validator; } // Add novalidate tag if HTML5. this.attr('novalidate', 'novalidate'); //HERE it is creating a new one using the constructor validator = new $.validator( options, this[0] ); $.data(this[0], 'validator', validator); </code></pre> <p>Apparently the <code>rules</code> method assumes that validator is already there in the form object, so from my understanding, and since <code>validate</code> returns validator instance, you can call <code>validate</code> and then append your extra rules to the returned validator <code>settings.rules</code> object and re-run again which is not very practical.</p> <p>The other solution would be to simply append the added rules to the initial rules object before calling <code>validate</code></p> <p>So in my case I wanted the input field to be validated as number however I didn't want Google Chrome to make it a number field (just try in Chrome to see what I mean, this had the issue of bypassing the type number validation in case the user entered manually, and in my case the user will most probably enter the number manually)</p> <p>code example:</p> <pre><code>var customRule = {number: true}; //suppose populateValidateRules() fills your initial rules, which is my case at least var validationRules = populateValidateRules(); validationRules["rules"].fieldToBeDynamicallyModifiedForValidation= customRule; $(formId).validate(validationRules); </code></pre> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload