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

Formslib - add function to $mform that makes it possible to hide form elements dependent on selected values

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      • Save the attached formhideiftestpage.php file into the Moodle root directory.
      • Visit [site]/formhideiftestpage.php
      • Check that each of the following situations work as expected:
        • 'Select yesno example' = 'Yes' - 'Test eq hideif' visible
        • 'Select yesno example' = 'No' - 'Test eq hideif' hidden
        • 'Checkbox example' = checked - 'Test not checked hideif' visible, 'Test checked hideif' hidden
        • 'Checkbox example' = not checked - 'Test not checked hideif' hidden, 'Test checked hideif' visible
        • 'Select example' = 3 or 4 - 'Test in hideif', 'Date time example' and 'Files' visible
        • 'Select example' = 1, 2 or 5 - 'Test in hideif', 'Date time example' and 'Files' hidden
      • Submit the form in each case. Only visible fields should be included in the listed submission data (with the exception of the 'testdatetime' field, which will be listed as 0, as is the standard behaviour of date_time_selectors with no data submitted).
      • Repeat the above test and use a screen reader. Make sure hidden elements are not announced to the user.
      Show
      Save the attached formhideiftestpage.php file into the Moodle root directory. Visit [site] /formhideiftestpage.php Check that each of the following situations work as expected: 'Select yesno example' = 'Yes' - 'Test eq hideif' visible 'Select yesno example' = 'No' - 'Test eq hideif' hidden 'Checkbox example' = checked - 'Test not checked hideif' visible, 'Test checked hideif' hidden 'Checkbox example' = not checked - 'Test not checked hideif' hidden, 'Test checked hideif' visible 'Select example' = 3 or 4 - 'Test in hideif', 'Date time example' and 'Files' visible 'Select example' = 1, 2 or 5 - 'Test in hideif', 'Date time example' and 'Files' hidden Submit the form in each case. Only visible fields should be included in the listed submission data (with the exception of the 'testdatetime' field, which will be listed as 0, as is the standard behaviour of date_time_selectors with no data submitted). Repeat the above test and use a screen reader. Make sure hidden elements are not announced to the user.
    • Affected Branches:
      MOODLE_30_STABLE, MOODLE_34_STABLE
    • Fixed Branches:
      MOODLE_34_STABLE
    • Pull Master Branch:
      MDL-53848_form_hideif

      Description

      Hi there,

      this ticket is close to the tickets MDL-49363 and MDL-52167 but not only requested for the adminlib but for the formslib.

      With this issue I would like to enhance the user experience and the usability.
      At the moment, activity / resource settings can be grouped to different sections. For example in the assignment there are settings relating to Feedback types, Submission settings, Group submission settings and so on.

      Within those settings it's only possible to disable elements if a value of another specified element is chosen. But this element is still visible to the user. If a user cannot make a choice because of a disabled option, is this item important for him? Does he need to see all the elements he cannot change? Would it not be more user friendly if he just get to see the items that are important for him depending to his selection?

      Let me give you a short example of the group submission settings of the assignment activity:

      If a user decides that his participants should submit all for themselves, he chooses 'No' at the item 'Student submit in groups'. That's all he need to do and know in this case:

      Does he need to read through all the settings that can be set when group submission is enabled? I don't think so.

      The UI - only in this case - should present all the possible settings related to group submission mode:

      Futhermore, in our Moodle we have the situation that we admins locked the setting 'Require group to make submission'. So the option is locked and definitely disabled, however it's not visible via the mouse over effect as it is with the disabled if option and it does not change whether yes or no is chosen in 'Student submit in groups', So the dependency to the selection of the element ahead is not clear.
      It would be much clearer if just the form elements that are needed are also presented to the user.

      I propose for implementing a kind of hiddenif function to make a whole form element including its label invisible dependent on another element.

      Here's also a question for such a function in the forum:
      https://moodle.org/mod/forum/discuss.php?d=71658

      Cheers,
      Kathrin

        Attachments

        1. datetime_not_hiding.png
          datetime_not_hiding.png
          12 kB
        2. formhideiftestpage.php
          4 kB
        3. group_submit_no.png
          group_submit_no.png
          13 kB
        4. group_submit_yes.png
          group_submit_yes.png
          29 kB

          Issue Links

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  13/Nov/17