Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-60170

fieldset without legend


    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 3.3.2
    • None

      One of the issue reported by an accessibility audit we had was the absence of a label tag inside a fieldset tag.

      There were two solutions proposed :

      • replace the fieldset tag by a div tag (wich doesn't have any obligations)
      • add a meaningfull legend tag

      We quickly found that the first solution was the easiest and fastest to developp so this is the one I am presenting right now, but either of the two solutions can be applied to satisfy the accessibility issue.

      The problem
      The problem was spotted on the form at /user/editadvanced.php but it's touching every forms that have hidden fields.
      You have to read the html of the page, search for an hidden field, and see that they are included inside a legendless fieldset.

      The solution
      I've managed to cure the problem at the source, by modifying the lib/pear/HTML/QuickForm/Renderer/Tableless.php file.
      I've just replaced the openHiddenFieldsetTemplate by something that suited the need of this issue.

      you can see the diff here :

      diff --git a/lib/pear/HTML/QuickForm/Renderer/Tableless.php b/lib/pear/HTML/QuickForm/Renderer/Tableless.php
      index 5b444ac..9611355 100644
      --- a/lib/pear/HTML/QuickForm/Renderer/Tableless.php
      +++ b/lib/pear/HTML/QuickForm/Renderer/Tableless.php
      @@ -105,6 +105,11 @@ class HTML_QuickForm_Renderer_Tableless extends HTML_QuickForm_Renderer_Default
          var $_fieldsetsOpen = 0;
      +   // have to create "fake" fieldsets (div blocs) instead of fieldset with class hidden regarding the accessibility issue
      +   var $_fakeFieldsetOpen = 0;
      +   var $_fakeFieldsetOpenTemplate = "\n\t<div>";
      +   var $_fakeFieldsetCloseTemplate = "\n\t</div>";
           * Array of element names that indicate the end of a fieldset
           * (a new one will be opened when a the next header element occurs)
      @@ -172,6 +177,12 @@ class HTML_QuickForm_Renderer_Tableless extends HTML_QuickForm_Renderer_Default
           function renderElement(&$element, $required, $error)
      +        // test to see if any fakefieldset open -> so we can close it here
      +        if($this->_fakeFieldsetOpen > 0) {
      +            $this->_html .= $this->_fakeFieldsetCloseTemplate;
      +            $this->_fakeFieldsetOpen--;
      +        }
               // if the element name indicates the end of a fieldset, close the fieldset
               if (   in_array($element->getName(), $this->_stopFieldsetElements)
                   && $this->_fieldsetsOpen > 0
      @@ -182,8 +193,9 @@ class HTML_QuickForm_Renderer_Tableless extends HTML_QuickForm_Renderer_Default
               // if no fieldset was opened, we need to open a hidden one here to get
               // XHTML validity
               if ($this->_fieldsetsOpen === 0) {
      -            $this->_html .= $this->_openHiddenFieldsetTemplate;
      -            $this->_fieldsetsOpen++;
      +            // instead of using openHiddenFieldset, we use <div> regarding the accessibility issue
      +            $this->_html .= $this->_fakeFieldsetOpenTemplate;
      +            $this->_fakeFieldsetOpen++;
               if (!$this->_inGroup) {
                   $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error);

      I am not familiar with XHTML validation so maybe there's a check to do there.
      Apart from that, I don't see any other issues that may be caused by this change.

      At first glance I didn't see any related issue. If so, we'll have to check that again to faceĀ a problem I may have missed.

      What do you think of it ?

      Have a nice day,

            Unassigned Unassigned
            tazoeur Guillaume Latour
            0 Vote for this issue
            2 Start watching this issue


                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.