PDA

View Full Version : How do I detect a form reset?



nickweavers
29 Jun 2010, 3:08 AM
I looked at the API but still wasn't sure how to do this. I also searched the forums and found this thread (http://www.sencha.com/forum/showthread.php?81992-Detect-native-event-support.&highlight=detecting+form+reset) which was interesting, but didn't really answer my question since I couldn't find anything in the API about Ext.capabilities.

The list of public events for basicForm are actioncomplete, actionfailed and beforeaction. Would this be used something like this:


myForm.getForm().on('actioncomplete', function (form, action) {
if (action == 'reset') {
// do custom post reset init
...
}
});

Or is it possible to do something like


myForm.getForm().on('reset', function (form, action) {
// do custom post reset init
...
}


TIA,
Nick.

mankz
29 Jun 2010, 3:14 AM
Doesn't seem like there's a reset event, you could always use an interceptor function..?

nickweavers
29 Jun 2010, 3:58 AM
Thanks for your help. Do you mean that Ext doesn't provide a way to listen for the form reset event? Submit and Reset are both recognised javascript form events right? Is the "interceptor function" another way of accessing native browser events? How would I code one and call it?

Animal
29 Jun 2010, 5:02 AM
It's crazy that there's no event.

Add one:



Ext.override(Ext.form.BasicForm, {
reset : function(){
if (this.fireEvent("beforereset", this) !== false) {
this.items.each(function(f){
f.reset();
});
this.fireEvent("reset", this)
}
return this;
}
});

nickweavers
29 Jun 2010, 5:36 AM
Works a treat!

Many thanks Nige.

nickweavers
29 Jun 2010, 7:21 AM
Sorry, I was wrong and didn't state clearly what I wanted to do. Using the override means the reset event is visible to my listener:


NS2.employeeJobInfoForm.getForm().on('reset', function (form) {
form.findField('primary_job_cb').setValue('ON');
form.findField('primary_job_cb').hide();
});
But it seems that execution flow is through my listener first and then through the override code which does a 'this.fireEvent("reset", this)', which I guess performs the actual reset. What I really hoped for was the override to first reset all of the form fields and then for my listener to get called to set some initial values/properties (I guess at the "afterreset" stage). Is that possible, or do I need to change the override to remove the 'this.fireEvent("reset", this)' and replace it with the explicit settings I need for each field (effectively doing a manual custom reset)?

Animal
29 Jun 2010, 7:30 AM
The reset event fires after the reset has happened.

nickweavers
29 Jun 2010, 11:15 AM
Right, thanks. Yes, it was my problem.