From 9e8b29120192783a56440936eb15711334cb2fc8 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 1 Apr 2022 21:28:25 +0300 Subject: [PATCH] calling etemplate2.submit(,,no_validation=true) caused no submit (as invalid is no promise, but null) --- api/js/etemplate/etemplate2.ts | 61 ++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index 090d82d1d3..43393e93b8 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -970,34 +970,7 @@ export class etemplate2 // Get the form values const values = this.getValues(container); - // Trigger the submit event - let canSubmit = true; - let invalid = null; - if(!no_validation) - { - canSubmit = !(invalid = this.isInvalid(container, values)); - } - invalid?.then((widgets) => - { - let invalid_widgets = widgets.filter((widget) => widget); - - if(invalid_widgets.length) - { - // Show the first invalid widget, not the last - if(invalid_widgets[0] && invalid_widgets[0] instanceof et2_widget) - { - let messages = []; - let valid = invalid.isValid(messages); - invalid.set_validation_error(messages); - } - } - else - { - doSubmit(); - } - }); - - let doSubmit = function() + const doSubmit = () => { if(typeof async == 'undefined' || typeof async == 'string') { @@ -1030,9 +1003,39 @@ export class etemplate2 { this._widgetContainer.egw().debug("warn", "Missing menuaction for submit. Values: ", values); } - }.bind(this); + } + // Trigger the submit event + let canSubmit = true; + let invalid = null; + if(!no_validation) + { + canSubmit = !(invalid = this.isInvalid(container, values)); + invalid?.then((widgets) => + { + let invalid_widgets = widgets.filter((widget) => widget); + + if(invalid_widgets.length) + { + // Show the first invalid widget, not the last + if(invalid_widgets[0] && invalid_widgets[0] instanceof et2_widget) + { + let messages = []; + let valid = invalid.isValid(messages); + invalid.set_validation_error(messages); + } + } + else + { + doSubmit(); + } + }); + } + else + { + doSubmit(); + } return canSubmit; }