r3-team / r3

REI3 - Free and open low code
https://rei3.de
MIT License
359 stars 47 forks source link

Tri-state input for bool fields with allowed null value? #64

Closed TechInterMezzo closed 2 months ago

TechInterMezzo commented 2 months ago

Is it possible to have a tri-state input control instead of a normal toggle control for bool fields that allow null values? Or even better also allow to set the tri-state control for bool fields without null to represent an unset state. This way you would require the user to take action and set the field to either true or false. If the user is just skipping the field because of an oversight the frontend would display an error like for empty text fields that are required.

r3-gabriel commented 2 months ago

If the boolean attribute is set to not be nullable, the form automatically marks the input as "missing" if the state is not set to true or false. This helps the user to see if an input is not set.

In the case where the attribute can be NULL, the NULL state is valid and changing this behaviour retroactively would break many existing apps.

However, there is currently no way to return to the NULL state in boolean inputs, even if they are nullable. This is inconsistent and even while there are very few cases, where you´d want to return to a NULL state, we should allow this in one way or another.

TechInterMezzo commented 2 months ago

I see. Also misinterpreted how the bool input field worked. Basically it is tri-state but only if the initial value is NULL and you can't set it back to NULL.

r3-gabriel commented 2 months ago

Yes, that is how it works right now. It´s never been very important, but I would understand if there is a use case, where someone requires it to reset to NULL.

TechInterMezzo commented 2 months ago

@r3-gabriel Coming back to the bool input field. Right now the unset/null state is shown with a "-" on the right side like the false state. Would it be possible to center that "button" for the unset state? Maybe that could be an additional visual hint that it is unset and not false.

r3-gabriel commented 2 months ago

Centering the toggle switch on the boolean input would look more distinct for certain - but it might confuse users as the input would look really strange. A toggle switch, as the boolean is now, is only ever left or right. A mid-centered toggle would look broken to me.

I would suggest to avoid nullable booleans in the first place. Working with 2 states is much easier and makes it simpler for users as well. For this reason, even if its not nullable, I set defaults on forms for either true or false, so that a user never has to know about "nullable" booleans.

Because we cannot avoid nullable values in booleans in some cases, we need a way to display this. But for me, if I see the dash (signifying a NULL boolean value), I know my app did something wrong or I forgot a default value on the field.

Do you have a use case where you need the third (e. g. null) state regularly for your apps?

TechInterMezzo commented 2 months ago

I have some cases where a user has to set a state and can't just keep a default state. For example if defect hardware was found during a maintenance. If it would just default to true or false it could be overlooked. So it would be required to be set. But some users couldn't tell the difference between the default unset state and false. They didn't understand why the system would require them to take action because in their eyes it was already false besides there being a "-" instead of a "0". The current design is not wrong but I think about how I could make it more clear to those users without requiring further explanations.

r3-gabriel commented 2 months ago

Just so I understand you correctly: Does the NULL value need to exist at all (eg. it has a separate purpose to true/false)? Or is this about users needing to set a NULL to true/false to be able to save a record?

If it´s the later, you can set a field default value and then the boolean would always be true or false by default when creating a new record.

TechInterMezzo commented 2 months ago

It is the later but that is intended. The user has to set a value and not just rely on a default value. That input field should not be overlooked. The user has to decide if the answer for that field is yes or no. By giving the field no initial value the form would show an error for the required field if the user did not make an active choice to set it to true or false.

r3-gabriel commented 1 month ago

Makes sense. We´ll take a look at making the NULL state more visual distinct. Not sure, which form this will take yet.