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 ...'));
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
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 ...'));
... 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?
Found the field in the table for table "Page" and change the default to 1.
Now new pages default to one - checked.
Is this just for new records having a default value? Just use the $defaults array.
static $defaults = array (
'MyBoolean' => '1'
);
Hi UncleCheese,
Do i place this in the Page.php file?
And where if so?
Thank you
I got it, thank you
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.
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