Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJS:Simple表单忽略formBind_Javascript_Extjs_Extjs4 - Fatal编程技术网

Javascript ExtJS:Simple表单忽略formBind

Javascript ExtJS:Simple表单忽略formBind,javascript,extjs,extjs4,Javascript,Extjs,Extjs4,我有个小问题,好几天都让我发疯。我有一个表格面板: Ext.define('EC.view.PasswordPanel', { extend: 'Ext.form.Panel', alias: 'widget.pwdpanel', bodyPadding: 15, initComponent: function() { this.initialConfig = {url:'/password/'}; this.fieldDef

我有个小问题,好几天都让我发疯。我有一个表格面板:

Ext.define('EC.view.PasswordPanel', {
    extend: 'Ext.form.Panel',
    alias: 'widget.pwdpanel',

    bodyPadding: 15,

    initComponent: function() {
        this.initialConfig = {url:'/password/'};

        this.fieldDefaults = {
            labelAlign: 'right',
            labelWidth: 135,
            msgTarget: 'side',
            allowBlank: false,
            inputType: 'password'
        };

        //this.listeners =  {
            //// circumvent broken formBind
            //validitychange: function(comp, valid) {
                //this.down('button').setDisabled(!valid);
            //}};

        this.buttons = [{
            text: 'Change',
            formBind: true,
            scope: this,
            handler: function() {
                this.submit({
                    success: function(form, action) {
                        Ext.Msg.alert(
                            'Success',
                            '<p>Password change has been scheduled successfully.</p>' +
                                EC.DELAY_NOTICE);
                            form.reset();
                    },
                    failure: function(form, action) {
                        if ('result' in action &&
                            'msg' in action.result) {
                            Ext.Msg.alert('Error', action.result.msg);
                        }
                    }
                });
            }
        }];
        this.items = [ {
            xtype: 'textfield',
            name: 'pw_old',
            fieldLabel: 'Old password'
        }, {
            xtype: 'textfield',
            name: 'pw_new1',
            id: 'pw_new1',
            fieldLabel: 'New password',
            minLength: 8,
            maxLength: 16
        }, {
            xtype: 'textfield',
            name: 'pw_new2',
            fieldLabel: 'Confirm new password',
        } ];

        this.callParent(arguments);
    }
});
现在,验证工作非常正常,但是表单无效时“更改”按钮不会被禁用。要明确的是:当我按下它时,它不会提交,但我觉得它应该被禁用

我是不是做错了什么?第二个选项卡中的另一个表单面板工作正常

我可以使用我注释掉的侦听器来规避这个问题,但我知道它应该可以不使用


请随意指出任何愚蠢/糟糕的风格,我对ExtJS完全陌生。

这是ExtJS的明显缺陷,因为即使他们自己的作品也是一样的

但是,我发现了快速解决方法—添加到
initComponent
行:

this.on('afterrender', function(me) {
    delete me.form._boundItems;
});
这是

更新


该错误在4.0.7中已修复。

请确保这是一个extjs错误,您可以在Ext.form.Basic.getBoundItems中找到。此函数最初将boundItems初始化为空数组([]),因为它在呈现字段之前开始查询。下面是这个bug的修复方法

//Fix formBind
    Ext.form.Basic.override({
        getBoundItems: function() {
            var boundItems = this._boundItems;
            //here is the fix
            if(this.owner.rendered) {
                if (!boundItems) {
                    boundItems = this._boundItems = Ext.create('Ext.util.MixedCollection');
                    boundItems.addAll(this.owner.query('[formBind]'));
                }
            }
            return boundItems;
        }
    });
此修复程序全局应用,因此您不必总是在创建的每个表单上添加
'afterrender'
处理程序。
这是我相信您需要的初始声明的使用示例,
formBind:true,disabled:false
。disabled默认为false…我相信您的意思是“true”,但当我这样做时,它永远不会被启用。在我的另一个面板(虽然是一个带有工具栏的GridPanel)中,它也可以在禁用设置的情况下工作!森查知道这个虫子吗?我找不到关于它的任何东西…@hynek。但在sencha论坛上仍然没有答案。啊,这正是我的问题。它只是在“按钮”内部不起作用。我不想提及我在这件事上花了多少时间(
//Fix formBind
    Ext.form.Basic.override({
        getBoundItems: function() {
            var boundItems = this._boundItems;
            //here is the fix
            if(this.owner.rendered) {
                if (!boundItems) {
                    boundItems = this._boundItems = Ext.create('Ext.util.MixedCollection');
                    boundItems.addAll(this.owner.query('[formBind]'));
                }
            }
            return boundItems;
        }
    });