PDA

View Full Version : Being able to abort an Ext.form.Form's transaction.



Animal
12 Jul 2007, 7:19 AM
Things might happen to a form during aysnchronous processing. This is what is happening to me. By the time the requst has returned, the form has been destroyed. Callbacks then operate on a destroyed form and fail.

In Ext.form.Action implementations we need



run : function(){
this.form.txId = Ext.Ajax.request(...
}


and in Ext.form.BasicForm:



abortTransaction: function {
if (this.txId) {
Ext.Ajax.abort(this.txId);
delete this.txId;
}
}


Ext.form.BasicForm.destroy (when Form becomes an Ext.Component!!!!) should abort any outstanding transaction.

Animal
12 Jul 2007, 10:32 PM
In fact that didn't work. I had to add



Ext.override(Ext.form.Action.Load, {
success : function(response){
if (this.form.destroyed) {
return
}
var result = this.processResponse(response);
if(result === true || !result.success || !result.data){
this.failureType = Ext.form.Action.LOAD_FAILURE;
this.form.afterAction(this, false);
return;
}
this.form.clearInvalid();
this.form.setValues(result.data);
this.form.afterAction(this, true);
}
});


And have Ext.form.BasicForm.destroy set the flag.

This would be a common pattern for any element which may be manipulated by a callback.

If an object that is involved in the callback has been destroyed, the callback should not run.

Store's callbacks should check whether the Store has been destroyed.

jack.slocum
12 Jul 2007, 10:41 PM
While the abort idea is a good idea, don't you think it would make more sense to prevent destruction of the form while a transaction is in progress?

Animal
12 Jul 2007, 10:56 PM
Well, that's usually due to user intervention.

In my case, what's happening is that a double click on a grid row fires the dblclick event. The outside code in the KeyField (extends Ext.form.TextField) which created and showed the BasicDialog with the Grid inside, subscribes to that, and extracts the clicked Record, and populates the input field, and destroys the Dialog which destroys the Grid etc etc.

The first click of the double click fires an event which the component used in that Dialog uses to populate its preview pane with the details of that row. But by the time the data comes back from the server, the double click handler in KeyField has destroyed everything.

I can't just refuse to destroy if a request is in progress, because the double click handler only runs once, and the user would be left with the popup record selector on their screen with no explanation.