parsley.js how to trigger an error on a field with a custom error message

riccardolardi picture riccardolardi · Jan 15, 2014 · Viewed 16.8k times · Source

It would be great if it was possible to do such thing as

$('input.specific-field').parsley('error', 'this is a custom error message');

...but I guess that isn't possible?

How could I achive such thing?

Answer

deadwards picture deadwards · Apr 23, 2014

Parsley has some built-in ways of adding custom error messages.

var specificField = $('input.specific-field').parsley();
# add the error
window.ParsleyUI.addError(specificField, "myCustomError", 'this is a custom error message');
# remove the error
window.ParsleyUI.removeError(specificField, "myCustomError");

More info here: http://parsleyjs.org/doc/index.html#psly-ui-for-javascript

EDIT: This method is now deprecated (thanks to @giraff).