【发布时间】:2015-05-07 16:38:24
【问题描述】:
当容器有 hidden: true 而不是实际字段时,我如何不验证隐藏字段
为了解决这个问题,我做了以下覆盖,它成功了,尽我所能不影响正常的验证流程,所以代码看起来不太好。
/* traverse up and look for a hidden Parent/Ancestor */
Ext.override(Ext.form.field.Base, {
isParentHidden: function () {
return this.up('[hidden=true]');
}
});
/* override isValid basic method to consider skipValidateWhenHidden property,
when skipValidateWhenHidden is set to true code should check if the elementor it's Parent/Ancestors is hidden */
Ext.override(Ext.form.field.Base, {
isValid: function () {
var me = this,
disabled = me.disabled,
isHidden = me.isHidden(),
skipValidateWhenHidden = !!me.skipValidateWhenHidden,
validate = me.forceValidation || !disabled,
isValid = validate ? me.validateValue(me.processRawValue(me.getRawValue())) : disabled;
if (isValid || !skipValidateWhenHidden) {
return isValid;
}
if (skipValidateWhenHidden) {
isHidden = isHidden ? true : me.isParentHidden();
if (isHidden) {
return skipValidateWhenHidden;
}
}
return isValid;
}
});
最终我将能够执行以下操作,将字段上的属性设置为 true,因此如果它对用户不可见,它将在验证后继续存在
{
itemId: 'City',
cls: 'AddressCity',
xtype: 'textfield',
emptyText: emptyCityText,
skipValidateWhenHidden: true,
},
【问题讨论】:
标签: javascript extjs extjs4 extjs4.1