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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Checkbox in admin cannot be "unchecked"


Go to End


2 Posts   1955 Views

Avatar
mschiefmaker

Community Member, 187 Posts

11 February 2009 at 1:52pm

Hi

I have added a checkbox to the admin area which allows the adminstrator to indicate whether they want a section of a page to be displayed or not.

class Page extends SiteTree {
static $db = array(
);
...,
'ContactUsValue' => 'Boolean',
...
);
function getCMSFields() {
$fields = parent::getCMSFields();
..
$fields->addFieldToTab("Root.Content.Main", new CheckboxField ('ContactUsValue', 'Contact Us link?'), Content);
...
return $fields;
}
}

Clicking the checkbox reveals the section. The problem occurs when they decide they want to remove it again. When they return to the page in question the checkbox doesn't display a tick and checking, then unchecking and saving does not change the flag. Any ideas?

Thanks

MM

Avatar
mschiefmaker

Community Member, 187 Posts

27 February 2009 at 1:24pm

Oops - user error. This code works perfectly. Had put the boolen in static $has_one = array(} by mistake.