【问题标题】:extjs form markInvalidextjs 表单标记无效
【发布时间】:2011-03-03 17:40:37
【问题描述】:

我想直接从表单中使用 this.form.markInvalid。

我的表单中有 2 项:

代码:

  items: [
            { 
            fieldLabel: 'Name',
            name: 'name'
            }
            ,{
            id: 'e' ,
            fieldLabel: 'Email',
            name: 'email'
        }]

当用户点击一个按钮时,我正在调用this.form.markInvalid({'e':'email is invalid'});

我想用错误消息将电子邮件项标记为无效:“电子邮件无效”。

但是当我按下按钮时我收到一条错误消息:

this.form is undefined
 this.form.markInvalid({'e':'email is invalid'}); 

谢谢

【问题讨论】:

    标签: extjs


    【解决方案1】:

    您是否在按钮处理程序/侦听器中定义了正确的范围?

    注册到点击事件的函数应该可以访问this.form 属性。 this 在您的情况下可能指向按钮本身而不是 formPanel。

    您可以通过使用 createDelegate() 或在注册侦听器时添加额外参数轻松更改侦听器的范围,如下所示:

    myButton.on('click', function(){
        console.log(this, this.id);
    }, this); // <= notice the "this" argument here!
    

    但是! 你为什么要这样验证你的电子邮件?您可以轻松地将 vtype 添加到您的字段配置中,让 ExtJS 为您完成所有工作。

    items: [{ 
        fieldLabel: 'Name',
        name: 'name'
    },{
        id: 'e' ,
        fieldLabel: 'Email',
        name: 'email',
        vtype: 'email'
    }]
    

    【讨论】:

    • thx ChrisR,我的范围错了,如果使用 appWiki.main_panel.getForm().markInvalid({'e':'error'});
    • 另外,您对第二种验证方法是正确的。但我没有使用它,因为“电子邮件”字段只是未来功能的一个例子。无论如何-> THX!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多