Created
November 5, 2018 22:05
-
-
Save alberto56/22540d014f709cda9538032ff1e05ad0 to your computer and use it in GitHub Desktop.
Drupal patch field_group-8.x-1.x-2787179-26.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/field_group.libraries.yml b/field_group.libraries.yml | |
index e09631b..2b9a811 100644 | |
--- a/field_group.libraries.yml | |
+++ b/field_group.libraries.yml | |
@@ -11,6 +11,30 @@ field_ui: | |
- core/drupal | |
- core/drupalSettings | |
+details_validation: | |
+ header: false | |
+ version: VERSION | |
+ js: | |
+ js/field_group.details_validation.js: {} | |
+ dependencies: | |
+ - core/jquery | |
+ | |
+tab_validation: | |
+ header: false | |
+ version: VERSION | |
+ js: | |
+ js/field_group.tab_validation.js: {} | |
+ dependencies: | |
+ - core/jquery | |
+ | |
+tabs_validation: | |
+ header: false | |
+ version: VERSION | |
+ js: | |
+ js/field_group.tabs_validation.js: {} | |
+ dependencies: | |
+ - core/jquery | |
+ | |
core: | |
version: VERSION | |
js: | |
diff --git a/js/field_group.details_validation.js b/js/field_group.details_validation.js | |
new file mode 100644 | |
index 0000000..13a00fd | |
--- /dev/null | |
+++ b/js/field_group.details_validation.js | |
@@ -0,0 +1,26 @@ | |
+(function ($) { | |
+ 'use strict'; | |
+ | |
+ /** | |
+ * Behaviors for details validation. | |
+ */ | |
+ Drupal.behaviors.fieldGroupDetailsValidation = { | |
+ attach: function (context, settings) { | |
+ $('.field-group-details :input', context).each(function (i) { | |
+ var $field_group_input = $(this); | |
+ this.addEventListener('invalid', function (e) { | |
+ // Open any hidden parents first. | |
+ $(e.target).parents('details:not([open])').each(function () { | |
+ $(this).attr('open', ''); | |
+ }); | |
+ }, false); | |
+ if ($field_group_input.hasClass('error')) { | |
+ $field_group_input.parents('details:not([open])').each(function () { | |
+ $(this).attr('open', ''); | |
+ }); | |
+ } | |
+ }); | |
+ } | |
+ }; | |
+ | |
+})(jQuery); | |
diff --git a/js/field_group.tab_validation.js b/js/field_group.tab_validation.js | |
new file mode 100644 | |
index 0000000..3101d35 | |
--- /dev/null | |
+++ b/js/field_group.tab_validation.js | |
@@ -0,0 +1,22 @@ | |
+(function ($) { | |
+ 'use strict'; | |
+ | |
+ /** | |
+ * Make sure tab field groups which contain invalid data are expanded when they first load, and also | |
+ * when someone clicks the submit button. | |
+ */ | |
+ Drupal.behaviors.fieldGroupTabValidation = { | |
+ attach: function () { | |
+ var openTabsWithInvalidFields = function() { | |
+ $('.field-group-tab input:invalid').parents('details').children('summary[aria-expanded=false]').click(); | |
+ } | |
+ | |
+ // When a form is first loaded, open tabs with invalid fields. | |
+ openTabsWithInvalidFields(); | |
+ | |
+ // Also, when someone tries to submit a form, open tabs with invalid fields. | |
+ $('#edit-submit').on('click', openTabsWithInvalidFields); | |
+ } | |
+ }; | |
+ | |
+})(jQuery); | |
diff --git a/js/field_group.tabs_validation.js b/js/field_group.tabs_validation.js | |
new file mode 100644 | |
index 0000000..41db2d3 | |
--- /dev/null | |
+++ b/js/field_group.tabs_validation.js | |
@@ -0,0 +1,32 @@ | |
+(function ($) { | |
+ 'use strict'; | |
+ | |
+ /** | |
+ * Behaviors for tab validation. | |
+ */ | |
+ Drupal.behaviors.fieldGroupTabsValidation = { | |
+ attach: function () { | |
+ var fieldGroupTabsOpen = function ($field_group) { | |
+ if ($field_group.data('verticalTab')) { | |
+ $field_group.data('verticalTab').tabShow(); | |
+ } else { | |
+ if ($field_group.data('horizontalTab')) { | |
+ $field_group.data('horizontalTab').tabShow(); | |
+ } else { | |
+ $field_group.attr('open', ''); | |
+ } | |
+ } | |
+ }; | |
+ | |
+ var onInvalid = function(e) { | |
+ $inputs.off('invalid', onInvalid); | |
+ fieldGroupTabsOpen($(e.target).parents('details:not(:visible), details.horizontal-tab-hidden, details.vertical-tab-hidden')); | |
+ requestAnimationFrame(function () { $inputs.on('invalid', onInvalid); }); | |
+ }; | |
+ | |
+ var $inputs = $('.field-group-tabs-wrapper :input'); | |
+ $inputs.on('invalid', onInvalid); | |
+ } | |
+ }; | |
+ | |
+})(jQuery); | |
diff --git a/src/Plugin/field_group/FieldGroupFormatter/Details.php b/src/Plugin/field_group/FieldGroupFormatter/Details.php | |
index 8a78c6e..83c4e38 100644 | |
--- a/src/Plugin/field_group/FieldGroupFormatter/Details.php | |
+++ b/src/Plugin/field_group/FieldGroupFormatter/Details.php | |
@@ -53,6 +53,7 @@ class Details extends FieldGroupFormatterBase { | |
$element['#attached']['library'][] = 'field_group/formatter.details'; | |
$element['#attached']['library'][] = 'field_group/core'; | |
} | |
+ $element['#attached']['library'][] = 'field_group/details_validation'; | |
} | |
/** | |
diff --git a/src/Plugin/field_group/FieldGroupFormatter/Tab.php b/src/Plugin/field_group/FieldGroupFormatter/Tab.php | |
index 7cc8a64..3229128 100644 | |
--- a/src/Plugin/field_group/FieldGroupFormatter/Tab.php | |
+++ b/src/Plugin/field_group/FieldGroupFormatter/Tab.php | |
@@ -66,6 +66,8 @@ class Tab extends FieldGroupFormatterBase { | |
$element['#attached']['library'][] = 'field_group/core'; | |
} | |
+ $element['#attached']['library'][] = 'field_group/tab_validation'; | |
+ | |
$element += $add; | |
} | |
diff --git a/src/Plugin/field_group/FieldGroupFormatter/Tabs.php b/src/Plugin/field_group/FieldGroupFormatter/Tabs.php | |
index 4f49ec3..681bf71 100644 | |
--- a/src/Plugin/field_group/FieldGroupFormatter/Tabs.php | |
+++ b/src/Plugin/field_group/FieldGroupFormatter/Tabs.php | |
@@ -80,6 +80,7 @@ class Tabs extends FieldGroupFormatterBase { | |
} | |
} | |
+ $element['#attached']['library'][] = 'field_group/tabs_validation'; | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment