From 6363205f34cd544d661bab51bd2e920b26727b59 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Mon, 29 Sep 2014 14:04:05 +1000 Subject: [PATCH] Fixes validation on Tabs and Cms pages --- modules/backend/assets/js/october.tab.js | 4 +++- modules/cms/assets/js/october.cmspage.js | 4 +++- modules/system/assets/js/framework.js | 5 +---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/backend/assets/js/october.tab.js b/modules/backend/assets/js/october.tab.js index c53b6453c..2420f74c1 100644 --- a/modules/backend/assets/js/october.tab.js +++ b/modules/backend/assets/js/october.tab.js @@ -433,7 +433,9 @@ /* * Detect invalid fields, focus the tab */ - $(window).on('ajaxInvalidField', function(ev, element, name){ + $(window).on('ajaxInvalidField', function(event, element, name, messages, isFirst){ + if (!isFirst) return + event.preventDefault() element.closest('[data-control=tab]').ocTab('goToElement', element) element.focus() }) diff --git a/modules/cms/assets/js/october.cmspage.js b/modules/cms/assets/js/october.cmspage.js index 1785e11a8..ccf903e0d 100644 --- a/modules/cms/assets/js/october.cmspage.js +++ b/modules/cms/assets/js/october.cmspage.js @@ -57,7 +57,9 @@ /* * Detect invalid fields, uncollapse the panel */ - $(window).on('ajaxInvalidField', function(ev, element, name){ + $(window).on('ajaxInvalidField', function(ev, element, name, messages, isFirst){ + if (!isFirst) return + event.preventDefault() var $panel = element.closest('.form-tabless-fields.collapsed'), $primaryPanel = element.closest('.control-tabs.primary.collapsed') diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index 54c85fb29..781241d31 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -215,10 +215,7 @@ if (window.jQuery === undefined) $(window).trigger(_event, [fieldElement, fieldName, fieldMessages, isFirstInvalidField]) if (isFirstInvalidField) { - if (!_event.isDefaultPrevented()) { - // Bug in Chrome, calling events too early - setTimeout(function(){ fieldElement.focus() }, 1) - } + if (!_event.isDefaultPrevented()) fieldElement.focus() isFirstInvalidField = false } }