Fix #4323: TabbedForm validation switches to erroneous tab on every client form validation

This commit is contained in:
buddh4 2020-09-04 18:26:05 +02:00
parent cf10a561bc
commit 9fcc7b4e48
2 changed files with 13 additions and 6 deletions

View File

@ -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)
-----------------------

View File

@ -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
});