Ext JS –如果验证失败,则禁用FormPanel提交

时间:2019-01-16 05:04:37

标签: regex validation extjs textarea disable

在表单验证失败时,我无法禁用该按钮。我想使用正则表达式:/^[0-9]+(,[0-9]+)*$/进行文本区域验证。我想禁用activatebutton

我尝试了formBind,并且监控器验证仍然无效。

以下是代码:

items: [{
    xtype: 'container',
    layout: {
        type: 'column'
    },
    items: [{
        columnWidth: .75,
        layout: "form",
        monitorValid: true,
        items: {
            fieldLabel: 'Please Enter  Activation Id',
            name: 'Activate',
            xtype: 'textarea',
            msgTarget: 'under',
            growMax: 200,
            allowBlank: false,
            blankText: "Please Enter Comma separated AssetIds",
            regex: /^[0-9]+(,[0-9]+)*$/,
            anchor: '100%'
        }
    }, {
        columnWidth: .25,
        items: {
            xtype: 'button',
            name: 'button',
            id: 'activatebutton',
            width: 100,
            text: 'Set for auto-activation',
            formBind: true,
            listeners: {
                click: function () {
                    shared.Notifier.success('The requ  ');
                    this.seForActivation();
                },
                scope: this
            }
        }
    }]
}]

1 个答案:

答案 0 :(得分:0)

要使formBind工作,您需要拥有Ext.form.Panel。 表单面板将处理表单字段的检查,并在整个表单有效时调用formBind

以下代码将处理formBind,另请参见working FiddleExt.form.Panel documentation

{
    xtype: 'form',
    layout: 'column',
    items: [{
        columnWidth: .75,
        layout: "form",
        monitorValid: true,

        items: {
            fieldLabel: 'Please Enter  Activation Id',
            name: 'Activate',
            xtype: 'textarea',
            msgTarget: 'under',
            growMax: 200,
            allowBlank: false,
            blankText: "Please Enter Comma separated AssetIds",
            regex: /^[0-9]+(,[0-9]+)*$/,
            anchor: '100%'

        }
    }, {
        columnWidth: .25,
        items: {
            xtype: 'button',
            name: 'button',

            id: 'activatebutton',
            width: 100,
            text: 'Set for auto-activation',
            formBind: true,
            listeners: {
                click: function () {

                    shared.Notifier.success('The requ  ');
                    this.seForActivation();
                },
                scope: this
            }
        }
    }]