Hi. dhx.Form
has a private method called _addLayoutItem
. Among other things, this method is responsible for firing the appropriate events for each type of control. In the case of buttons, it does the following. As can be seen, after launching the click
event for the form, it is verified if the button is of type submit for the purpose of executing the submission of the form.
button_2.events.on(types_1.ItemEvent.click, function (e) {
e.preventDefault();
_this.events.fire(types_1.FormEvents.click, [name, e]);
_this.events.fire(types_1.FormEvents.buttonClick, [name, e]);
if (button_2.config && button_2.config.submit && _this.validate()) {
button_2.config.url && _this.send(button_2.config.url);
}
});
However, something interesting may happen. In my case I am using the “click” event of the form to change the view in my Optimus application. This means that when the line that tries to access the config property is reached the object in button_2.config
has been destroyed; throwing the corresponding error because the config object is cleaned up in the destructor
Form.prototype.destructor = function () {
this.events && this.events.clear();
this.layout && this.layout.destructor();
this.config = this._attachments = this._state = this._uid = this.container = this.events = this._isValid = null;
this.unmount();
};
I would suggest checking the existence of the config object first for cases where the user has destroyed the form using the button’s click event:
button_2.events.on(types_1.ItemEvent.click, function (e) {
e.preventDefault();
_this.events.fire(types_1.FormEvents.click, [name, e]);
_this.events.fire(types_1.FormEvents.buttonClick, [name, e]);
if (button_2.config && button_2.config.submit && _this.validate()) {
button_2.config.url && _this.send(button_2.config.url);
}
});
Greetings