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

Default for mform repeated elements does not work (and has never worked)

    Details

    • Testing Instructions:
      Hide

      Test1:

      1. copy repeatgrouptest.php in moodle site
      2. navigate to repeatgrouptest.php through browser
      3. Make sure field value is set to default value, as set in repeatgrouptest.php (change default value and make sure it is set accordingly)
        Note: Rules and disbaledif options will not work for above testcase
        Test 2:
      4. copy repeattest.php in moodle site
      5. navigate to repeattest.php through browser
      6. Make sure Limit value is set to 0 and is disabled.
      7. Select checkbox and limit field should be enabled.
      8. Enter text (alphanumeric) and you should see error message
      9. Try submit the form, it should not be submitted
      10. Click "Add 3 more fields", and you should be able to add more fields.
      11. Change limit values to numeric and enter some text in fields.
      12. Try submit form and check values. Make sure they are correct as set in form.

      Test 3:
      Follow MDL-30335 test instructions.

      Test 4:
      Run php unit for formslib_test.php

      Test 5:

      1. Create choice activity
      2. Make sure limit is set to 0
      3. Set Limit to enable and all limit fields should be enabled.
      4. Try enter alphanumeric characters in limit and make sure you see validation error
      5. Complete the form and save, make sure all values are saved properly.

      Test 6:
      Please also test some existing areas of Moodle that user repeat_elements and defaults. For example,

      1. In the qtype_calculated editing form, each answer should have a default answer length of 2, and a default tolerance of 0.01.
      2. In qtype_numerical, Accepted error should be set to 0 and alphanumeric value should not be saved. Trying to save alphanumeric will reset this to 0.
      Show
      Test1: copy repeatgrouptest.php in moodle site navigate to repeatgrouptest.php through browser Make sure field value is set to default value, as set in repeatgrouptest.php (change default value and make sure it is set accordingly) Note: Rules and disbaledif options will not work for above testcase Test 2: copy repeattest.php in moodle site navigate to repeattest.php through browser Make sure Limit value is set to 0 and is disabled. Select checkbox and limit field should be enabled. Enter text (alphanumeric) and you should see error message Try submit the form, it should not be submitted Click "Add 3 more fields", and you should be able to add more fields. Change limit values to numeric and enter some text in fields. Try submit form and check values. Make sure they are correct as set in form. Test 3: Follow MDL-30335 test instructions. Test 4: Run php unit for formslib_test.php Test 5: Create choice activity Make sure limit is set to 0 Set Limit to enable and all limit fields should be enabled. Try enter alphanumeric characters in limit and make sure you see validation error Complete the form and save, make sure all values are saved properly. Test 6: Please also test some existing areas of Moodle that user repeat_elements and defaults. For example, In the qtype_calculated editing form, each answer should have a default answer length of 2, and a default tolerance of 0.01. In qtype_numerical, Accepted error should be set to 0 and alphanumeric value should not be saved. Trying to save alphanumeric will reset this to 0.
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE
    • Pull Master Branch:
      wip-mdl-31498-default

      Description

      Copy the attached php file in the root of your moodle head (close to config.php)
      Call it with a browser.
      As you can see by watching at the code, there are defaults for grouped repeated fields. (lines: 25, 30 and 35 of the attached file)
      In spite of this, default are not applied to respective fields at runtime.

      Now go to the function repeat_elements
      at line 962 of HEAD/lib/formslib.php
      and change lines around 1000

      from

      $pos=strpos($elementname, '[');
      if ($pos!==FALSE){
          $realelementname = substr($elementname, 0, $pos+1)."[$i]";
          $realelementname .= substr($elementname, $pos+1);
      }else {

      to

      if (strpos($elementname, '[') !== FALSE){
          $realelementname = str_replace('[', '['.$i.'][', $elementname);
      } else {

      Call again the same file.
      Now defaults are applied!!!

      One more issue (but without solution, this one):

      by adding

      $fieldname = 'color[green]';
      $repeateloptions[$fieldname]['rule'] = 'numeric';

      to my attached code
      I get the error:

       QuickForm Error: nonexistent html element Element 'color[0][green]' does not exist in HTML_QuickForm::addRule()

      About the other $options of repeat_elements function:
      -> helpbutton: works
      -> type: works

      -> disabledif: I don't know
      -> rule: doesn't work
      -> default: is the main topic of this issue

        Gliffy Diagrams

          Attachments

          1. mformtest.php
            2 kB
          2. mod_form.php
            38 kB
          3. repeatgrouptest.php
            2 kB
          4. repeattest.php
            2 kB

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    14/May/12