XML/HTML代码
=================================================================================================
workaround部分仅对动态增加FieldSet时有用,而如果被添加的FieldSet可以被删除(remove或者destroy)时,校验仍然会产生错误的,此时必须将FieldSet中的每一个Field在BaseForm中remove掉。
代码如下
//Create the Form
testForm = new Ext.form.FormPanel({
name: "form1",
frame:true,
width: 350,
items: [{
xtype: "textfield",
name: "nom",
fieldLabel: "nom",
allowBlank: false
}]
});
//Render the form
testForm.render(Ext.get('idForm'));
//Create the fieldset
testFieldSet = new Ext.form.FieldSet({
name: 'testFieldSet',
autoHeight: true,
items: [{
xtype : "textfield",
name : "testtextvalid",
fieldLabel: "testDyn",
allowBlank: false
}]
});
testForm.add(testFieldSet); //add the fieldset to the formpanel
testForm.doLayout();
===========this is the workaround============
testFieldSet.form = testForm.getForm();
testForm.initFields.call(testFieldSet);
//delete testForm.form;原来是有这一行的,但加上后连getForm()都不好用了,去掉就没问题了
===========this is the workaround============
OK,一切恢复正常!
=================================================================================================
workaround部分仅对动态增加FieldSet时有用,而如果被添加的FieldSet可以被删除(remove或者destroy)时,校验仍然会产生错误的,此时必须将FieldSet中的每一个Field在BaseForm中remove掉。
代码如下
var f = fieldset.form || fieldset.ownerCt.getForm();
fieldset.items.each(function(item) {
f.remove(item);
});
fieldset.destroy();