我不知道为什么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/
答案 0 :(得分:1)
是肯定的。您缺少事件的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);
}
});