Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » CheckboxField bug

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 779 Views
  • amalet
    Avatar
    Community Member
    7 Posts

    CheckboxField bug Link to this post

    Hello

    I'm not sure where to report a bug so I'm posting it here in case anyone finds it useful.

    It happens when transforming a CheckboxField to readonly.

    The performReadonlyTransformation() method in CheckboxField creates a new CheckboxField_Readonly and passes the text value for 'Yes' or 'No' to the constructor:

    function performReadonlyTransformation() {
       $field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
       $field->setForm($this->form);
       return $field;   
    }

    The constructor then calls setValue(). However the setValue() method in CheckboxField_Readonly casts the value to an (int) and then tests it to set the value to either Yes or No.

    class CheckboxField_Readonly extends ReadonlyField {
       //...
       
       function setValue($val) {
          $this->value = (int)($val) ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No');
       }
    }

    Since the setValue() function is passed a string and casts it to an int, performReadonlyTransformation() always returns a field with the value 'No'.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: CheckboxField bug Link to this post

    http://open.silverstripe.org/ is where all the raised issues live

  • amalet
    Avatar
    Community Member
    7 Posts

    Re: CheckboxField bug Link to this post

    Tried to submit 2 tickets on open.silverstripe.org but got errors after clicking 'Create ticket'.

    There is also an bug in performReadonlyTransformation() in TreeDropdownField. The TreeDropdownField_Readonly that is created does not have a value. Since the constructor of TreeDropdownField does not take a parameter for the value it needs to be set by setValue().

    function performReadonlyTransformation() {
       return new TreeDropdownField_Readonly($this->name, $this->title, $this->sourceObject, $this->keyField, $this->labelField);
    }

    This object has no value. To correct this the value has to be set before returning the new object:

    function performReadonlyTransformation() {
    $tdfro = new TreeDropdownField_Readonly($this->name, $this->title, $this->sourceObject, $this->keyField, $this->labelField);
    $tdfro->setValue($this->value);
    return $tdfro;
    }

    779 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.