I have a bootstrap 3 form and I am using validator to validate forms.
I have succesfully implemented basic validations for sign-in forms and now I am implementing validation of change password form.
The form is as follows:
<form id="changepassword-form" role="form" data-toggle="validator" class="form-quote" action="/changepasswordpost" method="POST">
<input name="changepassword-id" type="hidden" value="{{ id }}"/>
<input name="changepassword-token" type="hidden" value="{{ token }}"/>
<div class="form-group row">
<div class="form-field col-md-12 form-m-bttm">
<input name="changepassword-password" type="password" placeholder="Nueva contraseña *" class="form-control required">
</div>
</div>
<div class="form-group row">
<div class="form-field col-md-12 form-m-bttm">
<input name="changepassword-password2" type="password" placeholder="Repita la nueva contraseña *" class="form-control required">
</div>
</div>
<button id="changepassword-submit" type="submit" class="btn btn-primary">Cambiar contraseña</button>
</form>
I see in the documentation that custom validation can be used so I have written the following validation intended to be used in the second password field:
custom: {
passwordmatch: function($el) {
var matchValue = $('#changepassworde-password').value()
if ($el.val() !== matchValue) {
return "Passwords do not match"
}
}
}
But I do not know where or how can I define this custom validation. I understand that once defined I should just apply data-passwordmatch=''
to second password field.