Checkbox behaviour

Hello all,
I have a question about the checkbox. Is it possible to have a checkmark “V” for true, “X”
for false, and empty for the null value? That would reflect the use case of a Boolean field in a database table.
Kind regards,
Mladen

Maybe this add-on could hep (haven’t checked its datamodel or tried this myself, but description seems right for you):

Unless you need this for a “table viewer”, if you want a field for
a tri-state/optional boolean, abusing the checkbox might not be a good
user-experience. The checkbox’s internal state is just true/false, where
“undecided” often falls under false.

Using an X for “explicit false” might make users think, that the field
is actually checked/true (standard behaviour of checkbox); colors are
usually of no help here (theming, color blind users, …). So you would
have to change the text of the field as well and at that point you might
just use a radio-button-group or a combo-box.

If your “undecided” is actually an “not yet decided”, you might also
have to care for disallowing the “undecided” option once a decision was
made.

5 Likes

Thank you, this helps with understanding what is happening. :)

Thank you for this answer, it is really good, especially about the usage of the checkbox in this scenario. Luckily for me, the user scope in this case is limited to “trained users” so they would know the difference between V and X and empty for null, or maybe a ?. I also need to take care of the real estate in the grid, so I can’t use the radio group.
I think I will need to write a custom component, possibly a combobox as you suggested, with some icon representing the state.

Looking a the docs I noticed that the Vaadin Checkbox actually does support indeterminate mode, its value is Boolean (with capital), but just don’t allow having null value. Looks like creating a field that supports it was not too hard. Wrapped it with a CustomField and in value change listener I override it so that the value switches between null-> true → false → null…

I wonder if the name should be TriStateCheckbox though :thinking: Edit: I think so based on this related GH issue.

1 Like

Update regarding the other add-on I linked. Tested it a bit: it doesn’t use “null” as value in indeterminate state, but just provides a getter isIndterminate() that is missing from the Vaadin Checkbox API.