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

Unable to disable date_selector inside a form group

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not a bug
    • Icon: Minor Minor
    • None
    • 3.10
    • Forms Library
    • MOODLE_310_STABLE

      Given the following form:

       

      <?php
      require_once 'config.php';
      require_once $CFG->dirroot . '/lib/formslib.php';
      class myform extends moodleform {
       
          public function definition()
          {
              $this->_form->addGroup([
                  $this->_form->createElement('advcheckbox', 'c1', 'off'),
                  $this->_form->createElement('text', 't1'),
                  $this->_form->createElement('date_selector', 'd1'),
              ], 'group');
       
              $this->_form->addElement('date_selector', 'd2');
       
              $this->_form->disabledIf('group[t1]', 'group[c1]', 'checked');
              $this->_form->disabledIf('group[d1]', 'group[c1]', 'checked');
              $this->_form->disabledIf('d2', 'group[c1]', 'checked');
       
              $this->add_action_buttons();
          }
       
      }
       
      $PAGE->set_url(new moodle_url($_SERVER['REQUEST_URI']));
      $PAGE->set_context(context_system::instance());
       
      $page = optional_param('page', 'index', PARAM_TEXT);
       
      echo $OUTPUT->header();
       
      $form = new myform();
      $form->display();
       
      echo $OUTPUT->footer();
      

      Expected

      When I click the 'off' (c1) checkbox, the 3 fields (t1, d1 and d2) should all be disabled.

       

      Actual

      The t1 and d2 are disabled, but d1 is not (the date_selector inside the group).

       

      It seems that there is some problem presumably finding the element id, as the date_selector uses a group itself, so perhaps being a group inside a group is causing problems?

       

      I'm not sure if this a bug, or if I can resolve this by changing the `disabledIf` call in some way?

       

            Unassigned Unassigned
            cwarwicker CMR
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

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