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

repeat_elements does not work with groups that have $appendName = false

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.2
    • 2.2
    • Forms Library
    • MOODLE_22_STABLE
    • MOODLE_22_STABLE
    • Hide

      Save the attached testrepeatgroups.php in the top level of you moodle install, then go there (http://path.to.your/moodle/testrepeatgroups.php) and make sure the form works. That is:

      1. Inspect the HTML and look at what the name="" attributes are.

      2. Type in some data, and submit the form and look at the submitted data. (The test script just does print_object on the submitted data).

      3. (optional) edit the test script to try with other field types, etc. (But not that I have not attempted to fix MDL-20441 at this time.)

      Show
      Save the attached testrepeatgroups.php in the top level of you moodle install, then go there ( http://path.to.your/moodle/testrepeatgroups.php ) and make sure the form works. That is: 1. Inspect the HTML and look at what the name="" attributes are. 2. Type in some data, and submit the form and look at the submitted data. (The test script just does print_object on the submitted data). 3. (optional) edit the test script to try with other field types, etc. (But not that I have not attempted to fix MDL-20441 at this time.)

      When you add a group to a form, you can choose whether the field names get messed around with. This is the last argument to addGroup. That is, if you do

              $mform->addGroup(array(
                  $mform->createElement('text', 'a', 'A = '),
                  $mform->createElement('text', 'b', 'B = '),
              ), 'groupname', 'Fields', array(' '), false);

      The two fields end up with names a and b, but if you do

              $mform->addGroup(array(
                  $mform->createElement('text', 'a', 'A = '),
                  $mform->createElement('text', 'b', 'B = '),
              ), 'groupname', 'Fields', array(' '), true);

      The two fields end up with names groupname[a] and groupname[b].

      The problem comes when you try to use this in combination with repeat_elements. With $appendName = true, there is no problem. The field names become groupname[0][a], groupname[1][a], etc. The issue is with $appendName = false. Then, with the existing code, the field names are just a, b for each repeat, which means that the fields just overwrite each other.

      I am about to submit a patch so that with repeat_elements and $appendName = false, the field names are a[0], a[1]. b[0], b[1], etc.

            timhunt Tim Hunt
            timhunt Tim Hunt
            Colin Chambers Colin Chambers (Inactive)
            Aparup Banerjee Aparup Banerjee
            Rajesh Taneja Rajesh Taneja
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

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