Extjs 如何在Ext JS中为提交事件获取微粒字段的验证?

Extjs 如何在Ext JS中为提交事件获取微粒字段的验证?,extjs,sencha-touch,Extjs,Sencha Touch,下面是我的代码。 我有两个字段集,每个字段集包含一些文本框和一个按钮。 我只想验证按钮单击时属于该字段集的字段 例如,有两个选项:发送SMS和发送电子邮件。每个选项都有一个发送按钮。如果我想发送短信或电子邮件,那么我不想验证所有字段。这意味着,如果我想发送电子邮件,那么我只想验证电子邮件文本字段,而不是在单击电子邮件的发送按钮时验证SMS的字段 下面是我的代码。你可以更好地理解 this.form = new Ext.form.Panel({ margin: '10

下面是我的代码。 我有两个字段集,每个字段集包含一些文本框和一个按钮。 我只想验证按钮单击时属于该字段集的字段

例如,有两个选项:发送SMS和发送电子邮件。每个选项都有一个发送按钮。如果我想发送短信或电子邮件,那么我不想验证所有字段。这意味着,如果我想发送电子邮件,那么我只想验证电子邮件文本字段,而不是在单击电子邮件的发送按钮时验证SMS的字段

下面是我的代码。你可以更好地理解

  this.form = new Ext.form.Panel({
            margin: '10 100 10 100',
            xtype: 'panel',
            border: true,
            layout: 'hbox',
            padding: '2 2 2 2',
            items: [{
                xtype: 'fieldset',
                flex: 1,
                layout: 'anchor',
                title: 'Send Email',
                //collapsible: true,
                //collapsed: true,
                border: false,
                defaults: { anchor: '100%' },

                items: [{
                    xtype: 'textfield',
                    name: 'txtRecipients',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Recipients email address',
                    padding: '2 2 2 2 '
                },
                {
                    xtype: 'textfield',
                    name: 'txtSubject',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Subject',
                    padding: '2 2 2 2 '
                },
                {
                    xtype: 'textareafield',
                    name: 'txtMessage',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Type your message here',
                    padding: '2 2 2 2 ',
                    rows: 4

                },
                {
                    xtype: 'container',
                    items: [
                        {
                            xtype: 'button',
                            margin: '0 0 0 0',
                            text: 'Send',
                            width: 80,
                            height: 30,
                            handler: function () {
                            }
                        }
                    ]
                }]

            },
            {
                xtype: 'fieldset',
                flex: 1,
                layout: 'anchor',
                title: 'Send SMS',
                //collapsible: true,
                //collapsed: true,
                border: false,
                defaults: { anchor: '100%' },

                items: [{
                    xtype: 'textfield',
                    name: 'txtRecipients',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Contact Numbers seperated by comma(,)',
                    padding: '2 2 2 2 '
                },
                {
                    xtype: 'textareafield',
                    name: 'txt1Message',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Type your message here',
                    padding: '2 2 2 2 ',
                    rows: 3

                },
                {
                    xtype: 'tbspacer',
                    height: 45
                },
                {
                    xtype: 'container',
                    items: [
                        {
                            xtype: 'button',
                            margin: '0 0 0 0',
                            text: 'Send',
                            width: 80,
                            height: 30,
                            handler: function () {
                            }
                        }
                    ]
                }]

            }]
        });

您需要为每个按钮添加特定的功能。在每个角色中,您向电子邮件或SMS添加必要的验证

例如:

this.form = new Ext.form.Panel({
    margin: '10 100 10 100',
    xtype: 'panel',
    border: true,
    layout: 'hbox',
    padding: '2 2 2 2',
    items: [{
            xtype: 'fieldset',
            flex: 1,
            layout: 'anchor',
            title: 'Send Email',
            //collapsible: true,
            //collapsed: true,
            border: false,
            defaults: {
                anchor: '100%'
            },
            items: [{
                    xtype: 'textfield',
                    name: 'txtRecipients',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Recipients email address',
                    padding: '2 2 2 2 '
                },
                {
                    xtype: 'textfield',
                    name: 'txtSubject',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Subject',
                    padding: '2 2 2 2 '
                },
                {
                    xtype: 'textareafield',
                    name: 'txtMessage',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Type your message here',
                    padding: '2 2 2 2 ',
                    rows: 4

                },
                {
                    xtype: 'container',
                    items: [{
                        xtype: 'button',
                        margin: '0 0 0 0',
                        text: 'Send',
                        width: 80,
                        height: 30,
                        handler: function() {
                            check_email();
                        }
                    }]
                }
            ]
        },
        {
            xtype: 'fieldset',
            flex: 1,
            layout: 'anchor',
            title: 'Send SMS',
            //collapsible: true,
            //collapsed: true,
            border: false,
            defaults: {
                anchor: '100%'
            },
            items: [{
                    xtype: 'textfield',
                    name: 'txtRecipients',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Contact Numbers seperated by comma(,)',
                    padding: '2 2 2 2 '
                },
                {
                    xtype: 'textareafield',
                    name: 'txt1Message',
                    allowBlank: false,
                    //fieldLabel: 'Last Name',
                    emptyText: 'Type your message here',
                    padding: '2 2 2 2 ',
                    rows: 3

                },
                {
                    xtype: 'tbspacer',
                    height: 45
                },
                {
                    xtype: 'container',
                    items: [{
                        xtype: 'button',
                        margin: '0 0 0 0',
                        text: 'Send',
                        width: 80,
                        height: 30,
                        handler: function() {
                            check_sms();
                        }
                    }]
                }
            ]
        }
    ]
});

function check_email(){
    // Here you do a validation of the E-mail fields
}

function check_sms(){
   // Here you do a validation of the SMS fields
}

您只需将字段集xtype更改为form。因此,您可以直接验证并分别获取SMS和电子邮件的值