Jquery Validation Engine funcCall does not work, if only the rule

I have an input field in which I am trying to add a custom check (required depending on another field). If I put the required character AND funcCall (), I see that two errors are returned. If I just put funcCall, nothing will be returned. I know that it falls into the function and condition because I did console.log (), but for some reason it seems like it needs the original rule in order not to show the error.

Call:

<input type="text" class="validate[funcCall[validatePassportRequired]]" id="form_register_passport_number" value="" name="passport_number" size="50"> 

Functions:

 function validatePassportRequired(field, rules, i, options) { if ($('#register_for').val()!='Local') { return options.allrules.required.alertText; } } 

So, if I changed Call to:

 class="validate[required, funcCall[validatePassportRequired]]" 

I get two * This field is required

Should I have a different validation rule with funcCall?

+6
source share
2 answers

just add the following line before returning the error message and instead of the message required in the return, put the function name in front of .alertText.

 rules.push('required'); 

@sunzyflower in your case your function will look like this.

 function validatePassportRequired(field, rules, i, options) { if ($('#register_for').val()!='Local') { rules.push('required'); return options.allrules.validatePassportRequired.alertText; } } 
+12
source

Using

 funcCallRequired[validatePassportRequired] 

instead

 funcCall[validatePassportRequired] 

This will add an internal requirement without a double message.

If you need more information about the (old) issue:

+1
source

Source: https://habr.com/ru/post/943496/


All Articles