Sencha touch 2 Sencha touche表单验证

Sencha touch 2 Sencha touche表单验证,sencha-touch-2,Sencha Touch 2,我正在使用sencha touch创建我的第一个应用程序。 我对表单验证有问题。 表格如下: var form = new Ext.form.FormPanel({ title: 'Activity', items: [{ xtype: 'fieldset', items: [{ xtype: 'textfield', name : 'sector',

我正在使用sencha touch创建我的第一个应用程序。 我对表单验证有问题。 表格如下:

var form = new Ext.form.FormPanel({
        title: 'Activity',
        items: [{
            xtype: 'fieldset',
            items: [{
                xtype: 'textfield',
                name : 'sector',
                label: 'Sector',
                required: true
            },
            {
                xtype: 'selectfield',
                name : 'city',
                label: 'City',
                options: [
                {
                    text: '*',
                    value: '*'
                },
                {
                    text: 'First Option',  
                    value: 'first'
                },
                {
                    text: 'Second Option', 
                    value: 'second'
                },
                {
                    text: 'Third Option',  
                    value: 'third'
                }]
            },
            {
                xtype: 'textfield',
                name : 'nation',
                label: 'Nation',
                required: true
            },
            {
                xtype: 'toolbar',
                docked: 'bottom',
                layout: {
                    pack: 'center'
                },
                items: [{
                    xtype: 'button',
                    text: 'Cerca',
                    handler: function() {
                        formSettori.submit({
                            url: 'book.php',
                            method: 'GET',
                            success: function() {
                                Ext.Msg.alert('OK');
                            },
                            failure: function() {
                                Ext.Msg.alert('NO');
                            }
                        });
                    }
                },
                {
                    xtype: 'button',
                    text: 'Reset',
                    handler: function() {
                        form.reset();
                    }
                }]
            }]
        }]
    });
该表单只有三个字段: -活动 -城市​​ -国家

所有字段都是必填字段。 活动和国家不能是空的,而城市不应该是平等的*

如何控制这些字段?
谢谢大家!

没有内置的方式进行表单验证。你必须自己做

最简单的方法是使用private Ext.form.Panel方法循环遍历每个字段并确保它们不是空的

var fields = form.getFields(),
    field, name, isEmpty;

for (name in fields) {
    field = fields[name];
    isEmpty = (!field.getValue() || field.getValue() == "");

    if (isEmpty) {
        field.addCls('x-invalid');
    } else {
        field.removeCls('x-invalid');
    }
}

如果字段为空,那么我们将添加x-invalid类,以便您可以对其进行样式设置。

没有内置的方式来进行表单验证。你必须自己做

最简单的方法是使用private Ext.form.Panel方法循环遍历每个字段并确保它们不是空的

var fields = form.getFields(),
    field, name, isEmpty;

for (name in fields) {
    field = fields[name];
    isEmpty = (!field.getValue() || field.getValue() == "");

    if (isEmpty) {
        field.addCls('x-invalid');
    } else {
        field.removeCls('x-invalid');
    }
}
如果字段为空,那么我们将添加x-invalid类,以便您可以对其进行样式设置