From 9fcc7b4e4825baccd839bf387c420e1e6573539a Mon Sep 17 00:00:00 2001 From: buddh4 Date: Fri, 4 Sep 2020 18:26:05 +0200 Subject: [PATCH] Fix #4323: TabbedForm validation switches to erroneous tab on every client form validation --- protected/humhub/docs/CHANGELOG.md | 2 +- static/js/humhub/humhub.ui.form.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index 00b5416097..2c76618455 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -7,7 +7,7 @@ HumHub Changelog - Fix #4318: Timezone issue with LDAP and birthday fields - Fix #4342: Missing Emoji mappings used for plain richtext output - Fix #4343: Autofocus of picker input in modal not working - +- Fix #4323: TabbedForm validation switches to erroneous tab on every client form validation 1.6.2 (August 4, 2020) ----------------------- diff --git a/static/js/humhub/humhub.ui.form.js b/static/js/humhub/humhub.ui.form.js index 26dbee578c..2a15247a45 100644 --- a/static/js/humhub/humhub.ui.form.js +++ b/static/js/humhub/humhub.ui.form.js @@ -72,12 +72,15 @@ humhub.module('ui.form', function(module, require, $) { }); + this.$.on('submit', function() { + addValidationListener(); + }); + // activate the first tab or the tab with errors $tabs.find('a[href="#tab-' + activeTab + '"]').tab('show'); this.$.fadeIn(); }; - /** * Prepares all included fieldsets for $form indexed * by its label (legend). @@ -108,16 +111,16 @@ humhub.module('ui.form', function(module, require, $) { /** * Check for errors in a specific category. - * @param _object + * @param $fieldSet * @returns {boolean} */ var _hasErrors = function($fieldSet) { return $fieldSet.find('.error, .has-error').length > 0; }; - var init = function() { + var addValidationListener = function() { // Make sure frontend validation also activates the tab with errors. - $(document).on('afterValidate.humhub:ui:tabbedForm', function(evt, messages, errors) { + $(document).off('afterValidate.humhub:ui:tabbedForm').one('afterValidate.humhub:ui:tabbedForm', function(evt, messages, errors) { if (errors.length && Widget.exists('ui.form.TabbedForm')) { var index = $(errors[0].container).closest('.tab-pane').data('tab-index'); $('a[href="#tab-' + index + '"]').tab('show'); @@ -129,9 +132,13 @@ humhub.module('ui.form', function(module, require, $) { evt.$trigger.closest('form').submit(); }; + var unload = function() { + $(document).off('afterValidate.humhub:ui:tabbedForm'); + }; + module.export({ - init: init, sortOrder: 100, + unload: unload, submit: submit, TabbedForm: TabbedForm });