日期:2014-05-16 浏览次数:20437 次
Ext.override(Ext.layout.FormLayout, { renderItem : function(c, position, target){ if(c && !c.rendered && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){ var args = this.getTemplateArgs(c); if(typeof position == 'number'){ position = target.dom.childNodes[position] || null; } if(position){ c.itemCt = this.fieldTpl.insertBefore(position, args, true); }else{ c.itemCt = this.fieldTpl.append(target, args, true); } c.actionMode = 'itemCt'; c.render('x-form-el-'+c.id); c.container = c.itemCt; c.actionMode = 'container'; }else { Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments); } } }); Ext.override(Ext.form.Field, { getItemCt : function(){ return this.itemCt; } }); Ext.layout.FormLayout.prototype.trackLabels = true;
Ext.onReady(function(){ var c = 0; var testForm = new Ext.form.FormPanel({ name: "form1", frame:true, width: 850, items: [ new Ext.form.FieldSet({ id:'root', name: 'testFieldSet', autoHeight: true, title: 'fieldset', layout:'column', isFormField : true, layoutConfig:{ columns:2 }, collapsible: true, labelWidth: 60, items: [{ layout: 'form', columnWidth:.5, autoDestroy: true, items: [{ xtype : "textfield", name : "testtextvalid", fieldLabel: "----", frame:true, allowBlank: false }] }] }),{ xtype:'button', text:'test', handler: function (){ alert( Ext.getCmp('tx'+(c)) ); } },{ xtype: 'button', text: 'add', handler: function (){ c += 1; var testFieldSet = Ext.getCmp('root'); testFieldSet.add({ id:'te'+c, columnWidth:.5, layout: 'form', autoDestroy: true, items: [{ id: 'tx'+c, xtype : "textfield", name : "testtextvalid", fieldLabel: "extjs"+c, frame:true, allowBlank: false }] }); testFieldSet.doLayout(); testForm.doLayout(); testFieldSet.form = testForm.getForm(); } },{ xtype: 'button', text: 'del', handler: function (){ var fieldset = Ext.getCmp('root'); Ext.getCmp('tx'+c).destroy(); Ext.getCmp('te'+c).destroy(); fieldset.doLayout(); testForm.doLayout(); c -= 1; } } ,{ xtype: 'button', text: 'submit', handler: function (){ if(testForm.getForm().isValid()){ alert("yes"); }else{ alert("no"); } } } ] }); testForm.render(Ext.get('idForm')); });