Mootools Form.Validate未触发事件

问题描述 投票:2回答:1

我不知道为什么当输入失败时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/

javascript validation mootools mootools-events mootools-more
1个回答
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);
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.