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

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.5.2
    • FRONTEND
    • Forms Library
    • 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

              Unassigned Unassigned
              emerrill Eric Merrill
              Jake Dallimore, Mathew May, Mihail Geshoski
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: