From d367da6ba8a8943d80d16b044cefc9f2b19d35d5 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 5 May 2021 10:09:31 -0600 Subject: [PATCH] Etemplate: switch to tab of first invalid input, not last --- api/js/etemplate/etemplate2.js | 10 ++++++++++ api/js/etemplate/etemplate2.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/api/js/etemplate/etemplate2.js b/api/js/etemplate/etemplate2.js index ef86d84658..db51c7a328 100644 --- a/api/js/etemplate/etemplate2.js +++ b/api/js/etemplate/etemplate2.js @@ -675,9 +675,13 @@ var etemplate2 = /** @class */ (function () { var values = this.getValues(container); // Trigger the submit event var canSubmit = true; + var invalid = null; if (!no_validation) { container.iterateOver(function (_widget) { if (_widget.submit(values) === false) { + if (!invalid && !_widget.isValid()) { + invalid = _widget; + } canSubmit = false; } }, this, et2_ISubmitListener); @@ -704,6 +708,12 @@ var etemplate2 = /** @class */ (function () { this._widgetContainer.egw().debug("warn", "Missing menuaction for submit. Values: ", values); } } + else if (invalid !== null) { + // Show the first invalid widget, not the last + var messages = []; + var valid = invalid.isValid(messages); + invalid.set_validation_error(messages); + } return canSubmit; }; /** diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index 4c2ddca685..4527c68a26 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -858,12 +858,17 @@ export class etemplate2 // Trigger the submit event let canSubmit = true; + let invalid = null; if (!no_validation) { container.iterateOver(function (_widget) { if (_widget.submit(values) === false) { + if(!invalid && !_widget.isValid()) + { + invalid = _widget; + } canSubmit = false; } }, this, et2_ISubmitListener); @@ -900,6 +905,13 @@ export class etemplate2 this._widgetContainer.egw().debug("warn", "Missing menuaction for submit. Values: ", values); } } + else if (invalid !== null) + { + // Show the first invalid widget, not the last + let messages = []; + let valid = invalid.isValid(messages); + invalid.set_validation_error(messages); + } return canSubmit; }