Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Checkbox in admin cannot be "unchecked"

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

Page: 1
Go to End
Author Topic: 1097 Views
  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Checkbox in admin cannot be "unchecked" Link to this post

    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

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Checkbox in admin cannot be "unchecked" Link to this post

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

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