Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

(solved)CheckboxField unchecked as default in front end doesn't work


Reply


498 Views

Avatar
KimK

Community Member, 7 Posts

1 November 2012 at 10:55pm

Edited: 07/11/2012 11:33pm

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)