Reputation: 4509
I am asking this question for the second time because I didn't manage to solve the issue the last time.
I have a complex rule according to which I should validate user input. For the purpose of simplicity, let's assume that the input value should be divisible by 5. Consider this JsFiddle
var elem = $('#name').parsley();
var error_name = 'custom_error';
elem.removeError(error_name);
elem.addError(error_name, {message:'Custom error msg'});
Why is the reason this code does not work ?
Upvotes: 0
Views: 1712
Reputation: 79612
Much better to not use addError
and removeError
and to instead use a custom validator. There are good examples in the doc.
Upvotes: 1
Reputation: 37
Here's reference http://parsleyjs.org/doc/index.html#ui-for-field
Add the container to hold the message in the form
<p class="error-container"></p>
To Add the custom error
let specificField = $('#error-container').parsley();
window.ParsleyUI.addError(specificField, "myCustomError", "custom error text goes here ");
To remove the custom error
let specificField = $('#error-container').parsley();
window.ParsleyUI.removeError(specificField, "myCustomError");
$(".parsley-myCustomError").css("display", "none");
Upvotes: 0