PDA

View Full Version : Remove Field Extension



putty
16 Apr 2008, 5:53 PM
Hi all,

I am working on an extension that allows you to dynamically remove a field from a form, I have never created an extension before and I was after any comments and suggestions on what I have so far.

I used this extension as a base for my new one http://extjs.com/forum/showthread.php?t=19301

My extension seems to cancel out the extension above when they are both used in the same form. Dose anyone know how to fix that problem?

Cheers,
Levi

Extension
Ext.override(Ext.form.Field, {
afterRender : function() {
if(this.deleteable == true){

var field = this;
var label = findDeleteDiv(this);
var wrapDiv = field.getEl().up('div.x-form-item');

if(label)
{
var deleteImage = label.createChild({
tag: 'img',
src: '../content/images/icons/delete.png',
style: 'padding-left:3px; vertical-align: middle; text-align:justify;'
});

deleteImage.on('click', function() {
wrapDiv.remove(this);
field.destroy();
deleteImage.doLayout();
});

}
}
Ext.form.Field.superclass.afterRender.call(this);
this.initEvents();
}
});

var findDeleteDiv = function(field) {

var wrapDiv = null;
var div = null

wrapDiv = field.getEl().up('div.x-form-item');
if(wrapDiv)
{
div = wrapDiv.child('div');
}
if(div) {
return div;
}
}Usage
Ext.form.DateField({
fieldLabel: text,
name: fname,
format:'d/m/y',
deleteable:true,//<-- add delete icon next to field
anchor:'95%'
})