ui
ui copied to clipboard
Impl. nullable form field
When model field can be null, there needs to be an option to rended additional checkbox "null", i.e. allow user to set null value from Form/CRUD.
I don't see the point.
From UI point of view there is no null
value. It makes no sense for user. Standard user thinks that empty
is empty/no-value and he have no idea what null
means.
From data point of view of course we would like to store null
sometimes instead of empty values. That's what data normalization should do on atk4/data level. For example, convert empty string values to null, but don't convert integer 0 to null etc.
Speaking about checkbox I always think that checkbox is yes/no not yes/no/null type of field, but I have heard some objections that null should also be legit (undetermined) value of boolean field. Well, I don't agree with that. I think that if you need 3 states (null/yes/no), then you have to use dropdown (enum).
Here is my idea:
Add some form field property like
nullable
- set to false
by default, but if the programmer need an option to allow the control to be set a null - iit can be very easily set to true
and the right part of the example will be rendered.
It's possible to implement that of course. I'm not against any improvement in toolkit, but in this case I still I don't see real use-case for that. That will add complexity, but will be used very rarely. Maybe only if you try to build something like MySQL Workbench UI in Agile toolkit.
We considered this option. Null means lack of input and by design user always leaves some input when filling form fields. The case can be made for conditional fields eg if you have “has address 2” checkbox which enables extra fields. If not enabled, fields are hidden and user doors not get an opportunity to fill them out. In that case we can consider them null.
Text fields can be null (or empty text), but I think nobody will like to see that checkbox. I mean - users should not need to click additional checkbox just to be able to fill additional field. If they need to fill it then show field and if it's left empty it means user didn't want to fill it.
Another case is checkbox "Shipping address equals to billing address" in some kind of billing/checkout page of webshop. Then by clicking on it you can show up multiple other fields for input. Then then it's not related to null values at all. Then this checkbox acts just like a switch - enabled/disabled.
@mvorisek Here is a thought but that should be realised in combination with atk4/data:
- If field is nullable and required (both true), then null is accepted, but empty is not accepted.
- If a form field returns empty for such a field, it should save as null, and not empty string.
That way we can easily define by atk4/data what allowed and what not, and the Ui field should act accordingly.
In the past I have considered this several times, but there are two problems:
- MAJOR BC break
-
required
https://github.com/atk4/data/blob/7c09563967e866f02d0f483b164c2f2aec8a8b49/src/Model/FieldPropertiesTrait.php#L21 - will mean "disallow empty", to make field really required, you will have to setnullable
andrequired
But in my opinion we should do it 🚀. The current design is not ideal too, as nullable
itself does not tell if field can contain null or not.
@mvorisek Agree, we should do it - if field is really required (so the Form field also shows a "*" asterisk symbol), indeed we should set nullable = false
and required = true
. This makes a lot of sense.