Mootools Form.Validate 不会触发事件

发布于 2024-12-19 21:56:44 字数 1136 浏览 5 评论 0原文

我不知道为什么 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/

I don't know why the Form.Validate Class is not firing the events when an input fails. This is a simple test I've made:

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);
    }
});

but when I submit the form, in the console I only see "error". If I understood correctly the documentation, it should also fire the other two functions... I feel that I'm forgetting something.. any ideas?

here's the jsfiddle http://jsfiddle.net/HJX3K/2/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千と千尋 2024-12-26 21:56:44

是的。您缺少事件的 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);
    }
});

yes. you are missing on prefix for the events:

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);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文