I have created a content type and one of the fields needs to be a single checkbox. For example, I could have a label - Full driving licence - and a checkbox beside it.

So I created a field with the options -
Field: List(text)
Widget: Check boxes/radio buttons

and entered a single allowed value - Full Driving License.

But this is giving me two radio buttons to choose from -
N/A
Full Driving License

So how do I fix this? It should show just a checkbox for Full Driving License, there should be no radio buttons, and no N/A option.

Comments

steveburge’s picture

Hi ltwinner

Two solutions here:

1) Create a Boolean field .... that's Yes or No
2) Make your current field required .... that will remove the N/A option

ltwinner’s picture

OK, I made my current field required and it just gave me a single radio button that is already selected that I cant unselect. Do I have to do something else to make it a checkbox?

I would have imagined that this kind of functionality would be possible with drupal. Every 'Remember me' checkbox when you log into any website uses this functionality...

ltwinner’s picture

ah, I see, ty mate.

Sam2014’s picture

You can make it check boxes by making "Number of values" more than 1 while defining the field.

dwainash’s picture

This worked for me in D8. Thanks.

wranvaud’s picture

For info, this is set in the "BaseFieldDefinition::create" and the method needed is:

->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)

(you can set any number as cardinality or use the above for unlimited values)