I have change password screen and i want Current Password and New Password should not be same is there a way to do this using parsley
i also try with following condition but get no luck.
data_parsley_notequalto = "#controlId"
I have change password screen and i want Current Password and New Password should not be same is there a way to do this using parsley
i also try with following condition but get no luck.
data_parsley_notequalto = "#controlId"
This code worked well for me in many cases:
window.Parsley.addValidator("notequalto", {
requirementType: "string",
validateString: function(value, element) {
return value !== $(element).val();
}
});
You can use it like this:
<input type="text" id="test1" data-parsley-required>
<input type="text" id="test2" data-parsley-required data-parsley-notequalto="#test1" data-parsley-notequalto-message="These two fields must not be identical!">
I had the same question as you.
Then I found out you can create a custom validator.
Here's mine:
HTML:
<input type="text" id="myInput" data-parsley-notequalto="test" />
Add this before including parsley.js
window.ParsleyConfig = {
validators: {
notequalto: {
fn: function (value, id) {
return value !== $('#id').val();
},
priority: 32
}
},
i18n: {
en: {
notequalto: 'This value not equal to %s'
}
}
};
This will check if the value of #myInput
is equal to 'test'
. If equal it will display the error message specified.