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

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

    Details

    • Type: Improvement
    • Status: Reopened
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.9, 3.0
    • Fix Version/s: None
    • Component/s: Forms Library
    • Labels:
    • Affected Branches:
      MOODLE_19_STABLE, MOODLE_30_STABLE

      Description

      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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                19 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated: