From e4fa9eb83e9878b0c7df248f13b6516a776fcf74 Mon Sep 17 00:00:00 2001 From: camer0n Date: Fri, 5 Apr 2024 17:01:30 -0700 Subject: [PATCH] Fixes #5230 Invalid element tab switch issue. --- e107_web/js/core/admin.jquery.js | 10 +++++----- e107_web/js/core/front.jquery.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/e107_web/js/core/admin.jquery.js b/e107_web/js/core/admin.jquery.js index 77d57e021..2bde18a40 100644 --- a/e107_web/js/core/admin.jquery.js +++ b/e107_web/js/core/admin.jquery.js @@ -309,14 +309,14 @@ $(document).ready(function() /* Switch to Tab containing invalid form field. */ $('input[type=submit],button[type=submit]').on('click', function() { - + var id = $(this).closest('form').attr('id'); var found = false; - - $('#'+id).find('input:invalid,select:invalid,textarea:invalid').each(function(index, node) { - - var tab = $('#'+node.id).closest('.tab-pane').attr('id'); + + $('#'+id).find('input:invalid, input.has-error,select:invalid,select.has-error, textarea:invalid, textarea.has-error').each(function(index, node) { + var tab = $(this).closest('.tab-pane').attr('id');; + if(tab && (found === false)) { $('a[href="#'+tab+'"]').tab('show'); diff --git a/e107_web/js/core/front.jquery.js b/e107_web/js/core/front.jquery.js index fb97b16b4..d818b6be9 100644 --- a/e107_web/js/core/front.jquery.js +++ b/e107_web/js/core/front.jquery.js @@ -454,8 +454,15 @@ $(document).ready(function() $('#'+ id).find(':invalid').each(function (index, node) { - var tab = $('#'+node.id).closest('.tab-pane').attr('id'); - // console.log(node.id); + // Attempt to find a parent '.tab-pane' for the invalid input. + var tabPane = $(node).closest('.tab-pane'); + var tab = null; + + // Check if '.tab-pane' was found. + if(tabPane.length > 0) { + // If found, get the id of the '.tab-pane'. + tab = tabPane.attr('id'); + } if(tab && (found === false)) {