Score:0

How to let a boolean field on NULL if untouched?

id flag

Steps to reproduce my issue :

1- Add a boolean field to Article content type, not required, without touching default value

2- Edit an Article content without touching the boolean field.

3- Save the content.

4- The boolean field displays now FALSE value.

How to let this boolean field untouched and without any value (and thus hidden on full content display)?

cn flag
I would say that’s by design - a Boolean can only represent true or false, not a third value. A list field with a “N/A” option and complementary template logic might make more sense conceptually
Toki avatar
id flag
That makes sense indeed. But nodes created with Feeds import do not display boolean fields even if they should probably be on False too. So I was wondering if there would be a way to let the boolean field "empty" like Feeds does.
cn flag
That makes sense - if memory serves, it’s either the field widget or the checkbox element which casts the value to a bool when processed. So while you have the field on the form, I think it’ll be a bit awkward to change that logic
Toki avatar
id flag
I guess that logic is inappropriate in my case. The boolean field "Hydrophobe", for example, is set to "No" by default but my client can not tell until it has been tested. So I suppose I should switch to a List Text with three options (Not tested yet, Yes, No) as you suggested earlier. And I have 20 boolean fields...
cn flag
Yikes - another option might be to extend the core Boolean field with a custom type and see if you can intercept the part which does the casting
Toki avatar
id flag
It was my mistake at the beginning of the content type creation, wrong choice. Thanks for sharing your thoughts anyway.
Score:1
de flag

Not possible in the boolean field, it is possible to select the list field.

  • Create a list(text) field. It should be a single value to act as a radio button.
  • Change its widget from manage form display from the select list to checkbox/radio.

When you submit a node without touching the field it will have a null value.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.