Jump to:

22999 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » (solved)CheckboxField unchecked as default in front end doesn't work

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 334 Views
  • KimK
    Avatar
    Community Member
    7 Posts

    (solved)CheckboxField unchecked as default in front end doesn't work Link to this post

    Hi,

    I am new to silverstripe, php and here...

    I have a question regarding the difference between back end and front end behaviour of the CheckboxField.

    My problem:

    function getCMSFields() {

    $fields = new FieldSet( ...
    new CheckboxField('Question','Do you want to show this?', array(
    'true' => 'yes', 'false' => 'no')),
    ....
    );

    works like I expected the box is not ticked here in the back end,

    but if I use the same field for the front end

    function Form() {

          $fields = new FieldSet(...
    new CheckboxField('Question','Do you want to show this?', array(
    'true' => 'yes', 'false' => 'no')),
    ....
    );

    the box is ticked.

    I tried various combinations like

    1. $fields = new FieldSet(...
    new CheckboxField('Question','Do you want to show this?', array(
    'true' => 'yes', 'false' => 'no'), false),
    ....
    );
    2. $fields = new FieldSet(...
    new CheckboxField('Question','Do you want to show this?', array(
    'true' => 'yes', 'false' => 'no'), 0),
    ....
    );
    3. static $defaults = array(
    'Question' => 0
    );
    4. static $defaults = array(
    'Question' => false
    );

    nothing works...
    Is this a bug or what am I missing?

    I use SilverStripe 2.4.

    any ideas?

    maybe I should mention that I use the backend (function getCMSFields() {...) in DataObject

    STUPID ME I changed a former OptionsetField into CheckboxField and it's simply:
    $fields = new FieldSet(...
    new CheckboxField('Question','Do you want to show this?'), ...

    just a matter of copy and paste and not thinking properly error! - maybe somebody else will have the same problem, so I leave it posted - these mistakes to find just take so much time

    ...and I guess the most irritating was, that it worked properly in the back end (CMS fields)

    334 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.