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

Form element dependency options passed to repeat_elements do not work with MoodleQuickForm_group based elements

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Development in progress
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.9
    • Fix Version/s: None
    • Component/s: Forms Library
    • Labels:
    • Testing Instructions:
      Hide

      I could not find code example in Moodle to replicate this issue (that partly explains why this issue was not highlighted earlier), so please use attached script.

      1. Place script in Moodle wwwroot directory.
      2. Open script in the browser.
      3. Set test duration elements to 0 and observe that test elements disabling and hiding behaves as expected.
      4. Click "Add Repeats" and repeat step 3 with new (repeated) set of test elements.
      5. Repeat step 3 with original set of elements.
      6. (optional) Revert the patch and observe that behaviour is broken.
      Show
      I could not find code example in Moodle to replicate this issue (that partly explains why this issue was not highlighted earlier), so please use attached script. Place script in Moodle wwwroot directory. Open script in the browser. Set test duration elements to 0 and observe that test elements disabling and hiding behaves as expected. Click "Add Repeats" and repeat step 3 with new (repeated) set of test elements. Repeat step 3 with original set of elements. (optional) Revert the patch and observe that behaviour is broken.
    • Affected Branches:
      MOODLE_39_STABLE
    • Pull Master Branch:
      MDL-67909-master

      Description

      This happens when you are adding a dependency condition (disabledIf or hideIf) between elements used for repeated elements setup in the form. If the element used as target (the one which condition is checked) is part of the group (based on MoodleQuickForm_group such as Duration or addGroup itself), the conditional dependency will not work.

      To illustrate this, take the example:

      $repeatarray = [];
      $repeatarray[] = $mform->createElement('duration', 'testduration', 'testduration');
      $repeatarray[] = $mform->createElement('checkbox', 'testcheckbox', 'testdisableif');
       
      $repeatoptions = [
          'testcheckbox' => ['disabledif' => ['testduration[number]', 'eq', 0]]
      ];
      $this->repeat_elements($repeatarray, 1, $repeatoptions, 'test_repeats', 'test_add_fields');
      

      At the current state, setting duration field to 0 in the form, will not disable checkbox.

      This issue is related to the fact that when developer is passing disabledif and hideif options to repeat_elements, the name of the target element is not adjusted for new name that has been allocated when element was processed by repeat_elements function.

        Attachments

          Activity

            People

            Assignee:
            kabalin Ruslan Kabalin
            Reporter:
            kabalin Ruslan Kabalin
            Peer reviewer:
            Carlos Escobedo
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h