我有一个小问题让我疯狂了好几天。我有一个表单面板:
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);
}
});
我在TabPanel中实例化一个标签:
{
title: 'Change Password',
items: { xtype: 'pwdpanel' },
},
现在,验证工作完全正常,但在表单无效时未禁用“更改”按钮。要清楚:当我按下它时,不提交,但我觉得它应该被禁用?
我做错了吗?第二个标签中的另一个表单面板工作正常。
我可以使用我注释掉的监听器来避免这个问题,但我知道它应该没有用。
P.S。随意指出任何愚蠢/糟糕的风格,我对ExtJS完全不熟悉。
答案 0 :(得分:5)
这显然是extjs的错误,因为即使他们自己的example也是如此。
但是,我找到了快速的解决方法 - 添加到initComponent
行:
this.on('afterrender', function(me) {
delete me.form._boundItems;
});
这是fiddle。
<强>更新强>
该错误已在4.0.7中修复。
答案 1 :(得分:1)
当然,这是一个extjs错误,你可以在Ext.form.Basic.getBoundItems找到它。此函数最初将boundItems作为空数组([])启动,因为它在呈现字段之前开始查询。所以这是修复这个错误。
//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'
处理程序。
以下是使用http://jsfiddle.net/gajahlemu/SY6WC/