Validating a linked field in Parsley.js -


this question asked "jackrugile" on github can't located answer if ever given. i'm reposting here because having exact same issue:

when using validation constraints linked other fields (equal to, greater than, less than, before date, after date, etc.), whatever triggers validation call on 1 field should automatically called on other. applicable triggers other submit (focusin, focusout, keydown, keyup, etc.)

for example, if have field called "small number" , field called "large number", add data-greaterthan attribute "large number" input make sure larger. fill out field follows:

small number: 12 large number: 7 

this validation fails , error shows on on "large number" field. then, fix error, instead of making "large number" larger 12, make "small number" less 7. state of form now:

small number: 5 large number: 7 

however, though should pass because within validation rules, not remove error because no check performed on "large number" again after changing "small number".

what best solution this?

as far can tell, in parsley 2.1 (current version), not supported. however, can add functionality listening on parsley events fired. think there number of ways go this. have chosen on field initialization. when field initialized, if has validator depends on field, add listener field, such when field changes, re-execute validation. here example:

/**   * fields have comparison field,   * setup listener when 1 field changes, both   * fields re-validate.   */  $.listen('parsley:field:init', function(e) {    var comparisonfields = ['gte', 'gt', 'lte', 'lt'];    (var = 0; < comparisonfields.length; i++) {      if (e.optionsfactory.fieldoptions[comparisonfields[i]]) {         $(e.optionsfactory.fieldoptions[comparisonfields[i]]).on(e.optionsfactory.staticoptions.trigger, function() {           $(e.$element).parsley().validate();        })      }    }  }); 

note if add listener on init events, code must come before initialize parsley form.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -