Indicator for non-empty tabs

Created on 30 August 2024, 4 months ago

Problem/Motivation

Thank you for this useful module that is a good match for my usecase (where only 1 (or 2) fields in a content type are translated, on a node-by-node basis.
In my case, the description textarea will almost always have English, but on occasions will have any of French, Italian, Greek, etc. As things stand it is not obvious whether translated content exists. It would be better if there was a visual indication of the tabs for fields that contain content compared to the tabs for fields that are empty.

Steps to reproduce

Refer screenshot, where English and French content exists, but other translations are empty. There is no visual indication either way.

Proposed resolution

Add a visual indicator for tabs associated with non-empty fields. Will need to be based on javascript so that indicator can be added/removed to reflecting ongoing editing.

Remaining tasks

- Discuss approach
- Implement

User interface changes

See above.

Feature request
Status

Active

Version

1.0

Component

User interface

Created by

🇳🇿New Zealand jonathan_hunt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • 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);
    
Production build 0.71.5 2024