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.

Customising the CMS

Checkbox in admin cannot be "unchecked"


Reply

2 Posts   1204 Views

Avatar
mschiefmaker

11 February 2009 at 1:52pm Community Member, 187 Posts

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

27 February 2009 at 1:24pm Community Member, 187 Posts

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