- Issue created by @jonathan_hunt
- 🇳🇿New Zealand jonathan_hunt
fwiw, I attach js like the following, to a specific text area (Description) field to add/remove a class indicating content is present.
/** * Indicate whether Description tabs have content. */ (function (Drupal, once) { Drupal.behaviors.multilingual_form = { attach: function () { once('multilingual-form', 'html').forEach(function () { // Set initial indicator state, and add change listener. jQuery('.field--name-field-description.horizontal-tabs-panes details textarea').each(function(){ const tab_details = jQuery(this).closest('details'); const tab_details_id = '#' + tab_details.attr('id'); setNavItemForTextArea(tab_details_id); }).on('change',function(){ const tab_details = jQuery(this).closest('details'); const tab_details_id = '#' + tab_details.attr('id'); setNavItemForTextArea(tab_details_id); }); // Set has-content class based on contents of tab textarea. function setNavItemForTextArea(tab_details_id) { const navItemSelector = 'a[href="' + tab_details_id + '"]'; const hasContent = jQuery(tab_details_id + ' textarea').val() !== ''; if (hasContent) { jQuery(navItemSelector).addClass('has-content'); } else { jQuery(navItemSelector).removeClass('has-content'); } } }); } }; })(Drupal, once);