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

Forms lib throws fatal error if you add required rule to already required field

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.5.2
    • Fix Version/s: FRONTEND
    • Component/s: Forms Library
    • Labels:
    • Affected Branches:
      MOODLE_25_STABLE

      Description

      If you something like:

      $mform->addElement('editor', 'questiontext', get_string('questiontext', 'question'),
                       array('rows' => 15), $this->editoroptions);
      $mform->setType('questiontext', PARAM_RAW);
      $mform->addRule('questiontext', null, 'required', null, 'client');
      $mform->addRule('questiontext', null, 'required', null, 'client');
      

      You get a fatal (and non-sensical) error. While the above example is kinda ridiculous, it was found because a plugin wants to mark standard field as required, and we were changing the standard field to be required.

      This should do one of these:

      1. Be silent. (Probably just ignore the second rule)
      2. Throw a dev warning.
      3. Throw a sensical fatal message.

      I probably vote for number 2.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                emerrill Eric Merrill
                Participants:
                Component watchers:
                Jake Dallimore, Jun Pataleta, Ryan Wyllie
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: