PDA

View Full Version : [TIP] Destroy form every time !



Davi Baldin
21 Jul 2007, 12:18 PM
In specific context, i need to reder dynamic form with diferents fields. So with this code, i recreate without problem the form every time...

this code worksforme:


createForm : function(paramType,paramList) {
if(form) {
Ext.get('paramForm').remove();
form = null;
}

form = new Ext.form.Form({id: 'paramForm'});

and the object


ParametersEditorDialog = function(){

var form;
var dialog;

return {
createForm : function(paramType,paramList) {
if(form) {
Ext.get('paramForm').remove();
form = null;
}

form = new Ext.form.Form({id: 'paramForm'});

form.add(
new Ext.form.TextField({
fieldLabel: paramType,
name: 'first',
width:175,
allowBlank:false,
id: 'f1'
}));

//Render
form.render('parameters-dialog-form');
}
//... cuted here
};
//Function end
}();

thats is !!!

Davi

jay@moduscreate.com
22 Jul 2007, 4:19 PM
Yeah, once a form is rendered you do have to destroy it other wise you can't add things to it dynamically ,etc.

KRavEN
25 Jul 2007, 4:01 AM
To avoid giving the form an id, which I don't like doing:



if (form) {
form.el.remove();
form = null;
};