javascript 提交前的 Extjs 表单验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17248209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:38:14  来源:igfitidea点击:

Extjs Form Validation before Submit

javascriptformsvalidationextjsextjs4

提问by Noon

I have an Extjs form which it needs some validations like when I enter letters instead of numbers, it should alert me before I submit. direct before I enter one number in the field. How can I build that ?

我有一个 Extjs 表单,它需要一些验证,比如当我输入字母而不是数字时,它应该在我提交之前提醒我。直接在我在字段中输入一个数字之前。我怎样才能建立那个?

回答by Aminesrine

Try this:

试试这个:

onFormSubmit: function(btn, event) {
        var me        = this,
        form      = btn.up('form').getForm();
        if(form.isValid()) {
            //submit form
        }
        else alert('Invalid form');
    }

回答by Shahin Khalifa

buttons: [{
    text: "Continue",
    margin: "0 5 10 0",
    handler: function () {
        var getForm = this.up("form").getForm();
        if (getForm.isValid()) {
            code her if form is valid
        } else {
             Ext.MessageBox.show({
                title: "ERROR-A1001",
                msg: "Please fill the required fields correctly.",
                buttons: Ext.MessageBox.OK,
                icon: Ext.MessageBox.WARNING
            });
        }
    }
}]