react-ui-org / react-ui

React UI is a themeable and performant UI library for React apps.
https://react-ui.io
MIT License
21 stars 7 forks source link

implicitly required form fields visual #487

Open mbohal opened 1 year ago

mbohal commented 1 year ago

For some form fields:

The semantics of required are different then for fields such as TextField. When TextField is left empty, it means the user did not specify value. When one of the above mentioned special fields is left untouched, it still carries a meaning (e.g. false).

The above mentioned special fields are therefore always required as it is impossible not to fill them. Accordingly, they should always be styled as required fields even when they do not have the required attribute.

The required attribute on boolean fields means "must be set to true" which is different from its meaning when used with for example a TextField. When the required attribute is used in this sense, it must be communicated by other means, (e.g. by adding (required) to the label or such).

Note that HTML <select multiple> can be left with no selected value, but RUI does not implement this.

mbohal commented 5 months ago

In a video call we did not find agreement on the concept of implicitly required.

The solution we agreed on is to separate required HTML attribute from presentation details. There should be another prop that will render field in the "required" visual.

I'm unsure if the new prop (something like renderRequired or such) should be available on all Form Elements or only on Toggle, CheckboxField, SelectField, Radio.

adamkudrna commented 4 months ago

As I see it, I'd go with renderAsRequired on check fields (Toggle, CheckboxField, Radio) and on the SelectField.

Should both required and renderAsRequired be present, required would take precedence as it also adds the required HTML attribute.