javascript - Mootools Form.Validate 不触发事件

标签 javascript validation mootools mootools-events mootools-more

我不知道为什么 Form.Validate 类在输入失败时不触发事件。这是我做的一个简单测试:

HTML

<form id="IndicatorIndexForm" action="">
    <input type="text" id="IndicatorKilometers" data-validators="minLength:10" name="data[Indicator][kilometers]"/>
    <input type="submit" value="Valider" class="">
</form>

JS

var myForm = new Form.Validator($('IndicatorIndexForm'), {
    onFormValidate: function(resp,form,e){
        console.log('error');
    },
    elementFail: function(el,errors){
        console.log('elementFail');
        console.log(el);
        console.log(errors);
    },
    elementValidate: function(resp,el,validator,is_warning){
        console.log('elementValidate');
        console.log(resp);
        console.log(el);
        console.log(validator);
        console.log(is_warning);
    }
});

但是当我提交表单时,在控制台中我只看到“错误”。如果我对文档的理解正确,它还应该触发其他两个功能……我觉得我忘记了什么……有什么想法吗?

这是 jsfiddle http://jsfiddle.net/HJX3K/2/

最佳答案

是的。您缺少事件的 on 前缀:

var myForm = new Form.Validator($('IndicatorIndexForm'), {
    onFormValidate: function(resp,form,e){
        console.log('error');
    },
    onElementFail: function(el,errors){
        console.log('elementFail');
        console.log(el);
        console.log(errors);
    },
    onElementValidate: function(resp,el,validator,is_warning){
        console.log('elementValidate');
        console.log(resp);
        console.log(el);
        console.log(validator);
        console.log(is_warning);
    }
});

关于javascript - Mootools Form.Validate 不触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8399672/

相关文章:

mootools - 仅火狐浏览器 : TypeError: toggler is undefined

javascript - 如何扩展对象的原型(prototype)并在全局范围内具有相同的功能?

JavaScript Array.length 返回 0

javascript - 只允许 contenteditable 元素中的数字?

VBA:验证列表设置

javascript - 如何使用 Mootools 淡入淡出隐藏元素

javascript - 将日期和时间转换为 Unix 时间戳

javascript - 如何将多个变量从函数传递给jquery attr

php - 在每个字段旁边显示表单验证错误

mootools - 在这一点上,Mootorial 有多相关或过时?