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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

CheckboxField default on - checked


Reply


8 Posts   2900 Views

Avatar
steve_nyhof

Community Member, 224 Posts

5 January 2010 at 11:05am

How do I set my checkbox to default to the checked position?

$fields->addFieldToTab("Root.Content.Main", new CheckboxField('ShowHeadNav','Header Navigation: Check the checkbox ...'));

Avatar
steve_nyhof

Community Member, 224 Posts

5 January 2010 at 2:17pm

... new CheckboxField('ShowHeadNav','Header Navigation: ', 1));

I found this - adding the ,1 to the code. However, now that the tables are made, I cannot get it right. I have gone to the database to find the tables for this but do not see anything.

Ran dev/build/?flush=1 - still nothing is changing. The fields are gone in the editor, but when I update the code from Page.php it just adds the fields back in the way I left them.

Any ideas how to reset this, or remove the tables?

Avatar
steve_nyhof

Community Member, 224 Posts

5 January 2010 at 2:32pm

Found the field in the table for table "Page" and change the default to 1.

Now new pages default to one - checked.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

5 January 2010 at 2:52pm

Is this just for new records having a default value? Just use the $defaults array.

static $defaults = array (
'MyBoolean' => '1'
);

Avatar
steve_nyhof

Community Member, 224 Posts

5 January 2010 at 3:23pm

Hi UncleCheese,

Do i place this in the Page.php file?

And where if so?

Thank you

Avatar
steve_nyhof

Community Member, 224 Posts

5 January 2010 at 3:27pm

Edited: 05/01/2010 3:34pm

I got it, thank you

Avatar
UncleCheese

Forum Moderator, 4096 Posts

5 January 2010 at 3:42pm

Place it in whatever class contains the field for which you want a default value. If it is one of the core Page fields, e.g. "ShowInMenus", then put it there, but if it's a custom field you've added on a Page subclass, it belongs in that class.

Avatar
steve_nyhof

Community Member, 224 Posts

5 January 2010 at 6:05pm

Thank you, I added it under

class Page extends SiteTree {

Can you help me with this question, related to extend what I am doing here in the footer...

http://www.silverstripe.org/customising-the-cms/show/276269#post276269