-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable the required field on arrays and radio buttons #411
Comments
We've discussed this in the past already, I believe the jsonschema spec (which drives this lib implementation) wants But maybe I'm missing subtleties here; could you please create a jsfiddle highlighting the specific use case we're trying to cover here? Thanks! |
WIth regards arrays ... agreed. When this was raised I wan't aware of minItems. This has been resolved with better documentation. The other part of this particular Issue was with regards Radio Options. HTML allows for this control to use the "required" tag, and I think for consistency it should. The validation routine still works of course, but we're missing the additional HTML validation layer that other similar controls have. The specific change (if it was agreed) would be a one-liner ... in RadioWidget.js: <input type="radio"
checked={checked}
name={name}
required={required} <-------
... |
Oh, I see. Indeed, having native HTML5 validation for required radio boolean fields would be nice. We'd just need to ensure handling the recently introduced Could you create a PR from your commit? Thanks! |
No problem will do :) |
Highlights --- - Improved performance and reactivity. - More consistent validation behavior and UX for array field items. Backward incompatible changes --- - `ObjectField` and `ArrayField` are now stateless components, their local state handling has been dropped entirely, resulting in large performance improvements. - The `defaultFieldValue` helper from the `utils` module has been removed, as it wasn't used anymore. New features --- * Fix #411: Enable required field on radio options. (#469) * Spread `formContext` to `ArrayTemplateField`, `files` and `multiselect` arrays (#456) * From #471: Non-nullable array item fields are now marked as required in the UI. Bugfixes --- * Don't pass consumed `SchemaField` class names to child component (#439) * Turn `ObjectField` and `ArrayField` into stateless components (#480) * Fix #471: Drop default value initialization at the widget level. (#476) Kudos --- Special thanks to @crumblix and @knilink for their help on this release. You guys rock!
Released in v0.43.0. |
Prerequisites
Description
Following on from my last suggestion:
#410
I'd like to suggest enabling the "required" field on arrays and radio buttons.
If we make the changes I suggested in the above issue, we can enabled the "required" field on arrays. The use case would be where we want the user to select "at least one" checkbox in a list.
Also, the RadioWidget input supports the "required" tag, which in addition to being a nicer prompt for the user is also consistent with it's usage elsewhere in the module.
Steps to Reproduce
Attempt to make a radio button list mandatory, or an array mandatory.
For the radio widget instead of a clean "please fill in the field" message that we get when we use the mandatory tag, we get the errorlist returned.
If issue 410 is also addressed then we can make an array mandatory. Without 410 an empty array is still an array and so it won't work. With it we can make an array mandatory. We can't use the "required" HTML attribute, but at least the validation routines will return and prompt us with the error of the missing selection.
Expected behavior
For radio buttons: They should act like any other input that supports the "required" attribute.
For arrays (with 410): We should be able to make it possible to force the user to select "at least one" element in an array.
Actual behavior
Radio buttons go straight to the validation routine. While it works it's not as neat or consistent IMO.
You can't have mandatory arrays currently at all.
Version
Latest
Again here is the change in my fork:
Commit: a020837 [a020837]
The text was updated successfully, but these errors were encountered: