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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

CheckboxSetField: How to set checkbox fields


Go to End


4 Posts   936 Views

Avatar
Alist971

Community Member, 2 Posts

31 May 2015 at 11:48am

Edited: 03/06/2015 2:15am

Hi everyone !

I have this code which will generate me a list of checkbox:

CheckboxSetField::create(
	'genres',
	'Liste des genres',
	array(
		1 => 'Pop',
		2 => 'Jazz',
		3 => 'Rnb',
		4 => 'Trap',
	)
);

I want set some attributes of these future checkbox, for exemple there onclick attribut.

How can I do ? Some one can help me please ?

Avatar
Pyromanik

Community Member, 419 Posts

1 June 2015 at 10:55pm

Avatar
Alist971

Community Member, 2 Posts

3 June 2015 at 2:28am

Sorry if you're not understand me. it's a bit difficult to me to express myself in english. I'm not an anglophone.

Tanks for your answer.

What I want is custom the checkboxes in the CheckboxSetField class, by change some attributes before they will be printed in the template.

PS: Excuse my english ^^'

Avatar
Pyromanik

Community Member, 419 Posts

4 June 2015 at 8:11am

I understand English is not your language, don't worry :)

This is the CheckboxsetField template: https://github.com/silverstripe/silverstripe-framework/blob/3.1/templates/forms/CheckboxSetField.ss

You can copy it and put it in your templates folder (either in the theme or in your project [mysite/templates/forms/CheckboxSetFieldWithAttributes.ss])

Then you can edit it and use either
http://api.silverstripe.org/3.1/class-FormField.html#_setTemplate
or http://api.silverstripe.org/3.1/class-FormField.html#_setFieldHolderTemplate
on the field to make it use the new template (name it something different to CheckboxSetField.ss or it might always be used on CheckboxSetField)

Be sure to ?flush to make Silverstripe find the new template.