如何使 parsleyjs 仅在模糊时触发验证(对于验证失败的字段)

How to make parsleyjs only trigger validation on blur (for a field that has already failed validation)

我正在尝试弄清楚如何让 parsleyjs 仅针对 已经 验证失败的字段触发模糊验证。

http://jsfiddle.net/billyroebuck/zbmv2d3w/

标记:

<form id="myform">
    <label for="email">Email</label>
    <input type="email" name="email"
        data-parsley-required="true"
        data-parsley-type="email"
        data-parsley-custom
        data-parsley-trigger="blur"
    />
    <input type="submit" />
</form>

JavaScript:

window.Parsley.addValidator('custom',
function (value, requirement) {
    console.log('custom validation triggered');
    sleepFor(3000); // simulate a delay (testing only)
    if (value == 'test@test.com') {
        console.log('custom validation failed');
        return false;
    }
    console.log('custom validation passed');
    return true;
}, 32)
    .addMessage('en', 'custom', 'custom validation failed');

$('#myform').parsley();

function sleepFor(sleepDuration) {
    console.log('pretend this takes a while...');
    var now = new Date().getTime();
    while (new Date().getTime() < now + sleepDuration) { /* do nothing */
    }
}

parsleyjs 版本 2.2.0-rc1

电子邮件字段有验证规则要检查:

我将此字段的 parsley-trigger 属性设置为模糊。

步骤:

如何确保仅在无效字段的模糊事件上触发验证?

提前致谢!

恐怕目前没有这样的选项。想法是尽快删除错误消息,似乎每个人都喜欢这个。