PDA

View Full Version : field event on form reset.



nathanblogs
16 Feb 2010, 9:58 PM
Hi,

I've been reading the docs but I have been unable to find an event that is fired when a form clears(form.reset()) a field, is there one ?

Thanks

tobiu
16 Feb 2010, 10:55 PM
i miss this one too a lot, so +1 for feature request ;)

i would go this way:



Ext.form.BasicForm.override({
reset : function(){
this.items.each(function(f){
f.reset();
});
this.fireEvent('reset ', this);
return this;
}
});


untested though.

kind regards,
tobiu

evant
16 Feb 2010, 10:59 PM
Pretty reasonable. However, is the OP asking for the field to fire a reset event, or the form?

tobiu
16 Feb 2010, 11:08 PM
good question evant, i read it pretty fast ;)



Ext.form.BasicForm.override({
reset : function(){
this.items.each(function(f){
f.reset();
f.fireEvent('reset ', f);
});
this.fireEvent('reset ', this);
return this;
}
});


the green line may fit better to his needs, but it will only trigger on form.reset(), not if someone clears just one field.

kind regards,
tobiu (still voting to include the red line ;))

nathanblogs
16 Feb 2010, 11:29 PM
Thanks tobiu,

I ended up doing this, after the form reset which is basically the same.



form.items.each(function(){
this.fireEvent('reset', this);
});

Pretty reasonable. However, is the OP asking for the field to fire a reset event, or the form?

I really just need to know when a field gets reset, I have a combo box that displays different fields based on different options. Therefore if the form gets reset I need to set the fields back to the defaults. So the green line was what I needed.

tobiu
17 Feb 2010, 12:05 AM
similar, yes, but not basically the same:

you fire the event for each formElement with "this" pointing to the form ;)

Animal
17 Feb 2010, 12:48 AM
Set the reset event to bubble in Field.

Unfortunately there is a very longstanding Ext bug which I keep bothering them about in which the bubbleEvents config, and the method which processes it, enableBubble are in Container!!!!!!

So as supplied you cannot ask mere Components to bubble their events!!!

You can of course call Ext.Container.prototype.enableBubble.call(this, "reset") yourself.

But really, this bug should have been addressed.

tobiu
17 Feb 2010, 1:15 AM
hi nige,

i put the reset-listener for field into ext.form.field as suggested.
the new topic is here: http://www.extjs.com/forum/showthread.php?p=437889
since other users might find that needful too.

is there a reason, why the reset-method of basic form has a return-value (this) and the one of field has not?

+1 that enableBubble gets fixed some day too =)

kind regards,
tobiu