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

javascript error raised when strictformsrequired, autocomplete element and client validation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Minor
    • None
    • 4.0.8, 4.1.3, 4.2
    • Forms Library
    • MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE

    Description

      lib/formslib.php throws a JavaScript error when

      • a form has a required autocomplete element,
      • parameter multiple is true,
      • client-side validation is used and
      • 'strictformsrequired' parameter is enabled.

      getValidationScript() is expecting a string but getting an array
      https://github.com/moodle/moodle/blob/20302d4f8646fa367adbc48d6506d2aae07d7697/lib/formslib.php#L3434

      if (!empty($CFG->strictformsrequired))
          if (!empty($format) && $format == FORMAT_HTML) {
              return array('', "{jsVar}.replace(/(<(?!img|hr|canvas)[^>]*>)|&nbsp;|\s+/ig, '') == ''");
          } else {
              return array('', "{jsVar}.replace(/^\s+$/g, '') == ''");
          }
      }
      

      Steps to reproduce (4.2).
      0. Modify https://github.com/moodle/moodle/blob/20302d4f8646fa367adbc48d6506d2aae07d7697/admin/tool/cohortroles/classes/form/assign_role_cohort.php#L73 and add client-side validation rule

      $mform->addRule('cohortids', null, 'required', null, 'client');

      1. Open your JavaScript console.
      2. Login as admin, go to 'Site Administration > Security > Site security settings' and enable 'Strict validation of required fields'.
      3. Go to 'Site Administration > Users > Cohorts' and create a cohort.
      4. Go to 'Site Administration > Users > Define roles', edit role 'Student' and set 'user context' as a context type that can be assigned.
      5. Go to 'Site Administration > Permissions > Assign user roles to cohort' and select a cohort.
      You get an error: Uncaught TypeError: value.replace is not a function

      Attachments

        Activity

          People

            Unassigned Unassigned
            rovebd Roberto Bravo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Clockify

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