Moodle
  1. Moodle
  2. MDL-22513

Validation errors not displayed for grouped fields

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.9.8, 2.0.5, 2.1.2, 2.2
    • Fix Version/s: None
    • Component/s: Forms Library
    • Labels:
    • Testing Instructions:
      Hide

      As in the description.

      Show
      As in the description.
    • Workaround:
      Hide

      If you add the validation error to the group, that is

      $errors['groupname'] = 'Ha! I won\'t let you submit the form.';

      rather than to the field inside the group

      $errors['fieldname'] = 'Ha! I won\'t let you submit the form.';

      then the error displays. You can see this in the attached testgroupvalidation.php file, if you change which line in the validation function there is commented out.

      Show
      If you add the validation error to the group, that is $errors ['groupname'] = 'Ha! I won\'t let you submit the form.'; rather than to the field inside the group $errors ['fieldname'] = 'Ha! I won\'t let you submit the form.'; then the error displays. You can see this in the attached testgroupvalidation.php file, if you change which line in the validation function there is commented out.
    • Difficulty:
      Moderate
    • Affected Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Rank:
      2627

      Description

      See the attached test script testgroupvalidation.php. Save that into the top level of your Moodle install, then go there in your browser.

      Try to submit the form. You cannot, because the validation is hard-coded to fail. However, the validation error is not displayed, so it is impossible to know why you are not allowed to submit the form.

      The validation error should be displayed.

      1. attachement.txt
        3 kB
        Daniele Cordella
      2. testgroupvalidation.php
        1 kB
        Tim Hunt

        Activity

        Hide
        Tim Hunt added a comment -

        Just clarifying the description. This still affects all recent releases.

        Show
        Tim Hunt added a comment - Just clarifying the description. This still affects all recent releases.
        Hide
        Tim Hunt added a comment -

        Revised version of the test file that actually works.

        Show
        Tim Hunt added a comment - Revised version of the test file that actually works.
        Hide
        Tim Hunt added a comment -

        I just checked, and after the fix for MDL-30335 is integrated, the suggested work-around works, even for repeated groups.

        Show
        Tim Hunt added a comment - I just checked, and after the fix for MDL-30335 is integrated, the suggested work-around works, even for repeated groups.
        Hide
        Michael de Raadt added a comment -

        Thanks for reporting this issue.

        We have detected that this issue has been inactive for over a year. It was reported as affecting versions that are no longer supported.

        If you believe that this issue is still relevant to current versions (2.5 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

        Michael d.

        TW9vZGxlDQo=

        Show
        Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year. It was reported as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.5 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d. TW9vZGxlDQo=
        Hide
        Tim Hunt added a comment -

        I think the suggested work-around, which now works, is the right way to handle this situation. We use it a lot in the question forms. Therefore, I am closing this.

        Show
        Tim Hunt added a comment - I think the suggested work-around, which now works, is the right way to handle this situation. We use it a lot in the question forms. Therefore, I am closing this.
        Hide
        Daniele Cordella added a comment -

        I do not know it this issue is still alive
        but if so, why should you close it?

        Show
        Daniele Cordella added a comment - I do not know it this issue is still alive but if so, why should you close it?
        Hide
        Tim Hunt added a comment -

        I though I had explained already:

        The suggestion given in the workaround: add the validation error to the group, not the individual element inside the group, is the right way to use formslib. That is, it is not just a work-around. It is how the API should be used.

        I am not just saying that. All the quiz forms now work that way.

        Therefore, this is not a bug. Therefore, I closed it.

        Show
        Tim Hunt added a comment - I though I had explained already: The suggestion given in the workaround: add the validation error to the group, not the individual element inside the group, is the right way to use formslib. That is, it is not just a work-around. It is how the API should be used. I am not just saying that. All the quiz forms now work that way. Therefore, this is not a bug. Therefore, I closed it.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: