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.

Form Questions /

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

Checkbox in CMS form: no label to the left


Go to End


4 Posts   4975 Views

Avatar
Greengin

Community Member, 2 Posts

20 January 2015 at 6:31am

Hi, I have a form in the CMS, with a CheckboxField and other elements. The form is rendered in two columns, the left contains the field name (in bold style), and the right column contains the field control. This is for all the fields, except for the checkbox: a label appears next to the checkbox, which is fine, but the left column is empty, no bold field name there. How can I add a bold field name for checkboxes?

The code that creates the fields is:

$fields->addFieldsToTab('Root.Other', array(
        CheckboxField::create('Enabled'),
        TextField::create('Title', "Title"),
        TreeDropdownField::create("LinkID", "Linked page", 'SiteTree'),
        UploadField::create('Image', "Image")
    ));

Avatar
chasevida

Community Member, 7 Posts

9 February 2015 at 9:57am

Edited: 09/02/2015 9:57am

I feel like this is a fair use case that I also am having frustration with. It appears the 'Left Title' is pushed right and I can't reason why this is the case with this particular component. If you search google for workaround you get this post and one from 2007 (http://www.silverstripe.org/community/forums/archive/show/769) which has over a 1100 views and like this one no further comments, suggestions or solutions... cool.

Avatar
Terry Apodaca

Community Member, 112 Posts

31 July 2015 at 9:00pm

public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		//$fields->removeByName('Banner');
		//$fields->removeByName('Content');
		
		$fields->addFieldToTab(
			'Root.Sidebar',
			FieldGroup::create(
				CheckboxField::create('ShowSidebar','Show Sidebar on this page?')
			)->setTitle('Sidebar Options')->setName('SidebarOptions')
		);
		$fields->addFieldToTab('Root.Sidebar', TextField::create('SidebarTitle','Sidebar Title'));
		$fields->addFieldToTab('Root.Sidebar', TextField::create('SidebarText','Sidebar Content'));
	
		return $fields;
	}

Avatar
MyDogSez

Community Member, 1 Post

8 March 2016 at 7:14am

Edited: 08/03/2016 7:15am

The CheckboxSetField, distinct from the CheckboxField, takes as parameters the field name ('WhoDisplay'), the left column label ('Who Row Visibility'), and an array of checkbox key=value pairs (in this example only one, because it is a simple boolean).

$ArrayMap = array( '1'=>'Check to display Who row;<br />uncheck to remove');
$fields->addFieldToTab("Root.Main", new CheckboxSetField('WhoDisplay', 'Who Row Visibility', $ArrayMap));