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

Allow to set form element 'checkbox' value to something different than 1

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 1.9, 3.0
    • Forms Library
    • MOODLE_19_STABLE, MOODLE_30_STABLE

      In the file

      {moodesite}

      /lib/pear/HTML/QuickForm/checkbox.php there is a problem in the definition.

          function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null)
          {
              HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
              $this->_persistantFreeze = true;
              $this->_text = $text;
              $this->setType('checkbox');
              $this->updateAttributes(array('value'=>1));
              $this->_generateId();
          } //end constructor
      

      As you see, the value is always set to 1 no matter what developer sets in the addElement function.

      I think you need to check to see if a value if given. If one is given, no need to set the value =1.
      For example,

          function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null)
          {
              HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
              $this->_persistantFreeze = true;
              $this->_text = $text;
              $this->setType('checkbox');
              if (!isset($this->_attributes['value']) ) {
                  $this->updateAttributes(array('value'=>1));
              }
              $this->_generateId();
          } //end constructor
      

      This way, the value is only set to 1 if no value is given.

            jamiesensei Jamie Pratt (Inactive)
            bazaar Mawuli Kuivi (Inactive)
            Votes:
            18 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

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