parsley.js如何使用自定义错误消息触发字段上的错误

ric*_*rdi 6 html javascript css jquery parsley.js

如果有可能做这样的话会很棒

$('input.specific-field').parsley('error', 'this is a custom error message');
Run Code Online (Sandbox Code Playgroud)

......但我想这是不可能的?

我怎么能得到这样的东西?

dea*_*rds 14

Parsley有一些内置的添加自定义错误消息的方法.

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");
Run Code Online (Sandbox Code Playgroud)

更多信息:http://parsleyjs.org/doc/index.html#psly-ui-for-javascript

编辑:此方法现已弃用(感谢@giraff).


Mam*_*ter 2

也许是这个:

$('input.specific-field').parsley().UI.manageError({error: 'this is a custom error message'});
Run Code Online (Sandbox Code Playgroud)