By ltwinner on
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
Hi ltwinner Two solutions
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
OSTraining: Drupal video clases plus support
Drupal 7 Explained: The best-selling Drupal book
OK, I made my current field
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...
Option 1) Create a Boolean
Option 1) Create a Boolean field
OSTraining: Drupal video clases plus support
Drupal 7 Explained: The best-selling Drupal book
ah, I see, ty mate.
ah, I see, ty mate.
You're welcome, ltwinner
You're welcome, ltwinner
OSTraining: Drupal video clases plus support
Drupal 7 Explained: The best-selling Drupal book
Making Field options Checkboxes
You can make it check boxes by making "Number of values" more than 1 while defining the field.
Worked for me
This worked for me in D8. Thanks.
D8 code
For info, this is set in the "BaseFieldDefinition::create" and the method needed is:
(you can set any number as cardinality or use the above for unlimited values)