Created
July 16, 2020 19:46
-
-
Save mmenavas/8583291c6afed7545a93eb15b41031ed to your computer and use it in GitHub Desktop.
This snippet expands the details tags whenever a child form field fails browser validation
This file contains 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
(function ($, Drupal) { | |
Drupal.behaviors.openRequiredWrappers = { | |
attach: function (context, settings) { | |
// Prevent unnecessary multiple reloads. | |
if (context instanceof HTMLDocument) { | |
console.log("Test WDDSE-1913"); | |
var required_items = $('input,textarea,select').filter('[required]'); | |
required_items.each(function (index, el) { | |
// Add event listener that reacts when a form field fails validation. | |
$(el).on('invalid', function(e){ | |
// Expand all collapsed wrappers. | |
$(el).parents("details").each(function(index2, wrapper) { | |
wrapper.open = true; | |
}); | |
}); | |
}) | |
} | |
} | |
} | |
})(jQuery,Drupal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment