Closed (fixed)
Project:
radix
Version:
5.0.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
14 Aug 2020 at 06:11 UTC
Updated:
30 Mar 2023 at 14:04 UTC
Jump to comment: Most recent, Most recent file
Generated Radix subthemes currently do not include an asterisk to indicate a required input, seems like this might be useful default?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Screenshot 2021-08-11 at 13.47.00.png | 115.54 KB | doxigo |
| #2 | 3165175-asterisk-required-input.patch | 1018 bytes | bessone |
Comments
Comment #2
bessone commentedThis is because the asterisk in the core themes is displayed via CSS.
The attached patch fixes the problem for sub-themes by creating the necessary CSS lines in the kit, using the red indicated in the SCSS variables.
This works when creating a new sub-theme, for an already existing sub-theme you have to copy the changes.
Comment #3
ckngIt would be nice to have this available as an option OOTB. So suggest to make this optional by separating it to its own scss, so it could be enabled as needed. Perhaps
Primary argument is this is no longer provided since BS4. There are also other better UX, for references:
https://ux.stackexchange.com/questions/840/whats-the-best-way-to-highlig...
https://ux.stackexchange.com/questions/90685/using-asterisk-vs-required
Comment #4
doxigo commentedThere's a good article on this on ADG:
https://www.accessibility-developer-guide.com/examples/forms/required/
and some consideration on bootstrap docs as well:
https://getbootstrap.com/docs/5.0/forms/validation/
Comment #5
gngn commentedIn addition to indicating requiered fields I'd also like to mark fields with errors.
We could add something like
to components/form/_form.scss.
Styles are copied from core/themes/bartik/css/classy/components/form.css with using the red indicated in the SCSS variables.
Comment #6
doxigo commented@gngn, even though that sounds good but we should consider Bootstrap and not the things that Drupal core does
Comment #7
gngn commented@doxigo
According to the link you posted in #4 (https://getbootstrap.com/docs/5.0/forms/validation/) that means we should use
.is-invalid and .is-valid instead of .error?
How do we get those classes in the validation process?
Comment #8
doxigo commented@gngn I'd say yes, we should do what bootstrap is doing shown below:
I'll adjust this in the future, going to change the title to reflect the conclusion
Comment #9
gngn commented@doxigo that looks good - but I do not see the required classes
.is-invalid(and.is-valid) in my validated form.There is only core's
.error.What do I need to do to get the bootstrap classes?
Did I miss something while creating the sub theme?
Comment #10
trudog commentedValidation reflects Bootstrap 5 approach with a little extra work. My fix was as follows:
1. add class .needs-validation to form (
$form['#attributes']['class'][] = 'needs-validation';);2. in validateFrom(), if $form_state->getErrors() is not empty, add .was-validated class to form. (
if (!empty($form_state->getErrors()) { $form['#attributes']['class'][] = 'was-validated'; })At this point, everything looks like this https://getbootstrap.com/docs/5.0/forms/validation/#custom-styles
Additionally, use type email and tel for e-mail and phone fields. For type tel, you could also use pattern attribute to avoid a valid feedback when typing "asdf" instead of a phone number.
Comment #11
doxigo commentedThis is fixed for now but we probably have to consider clientside validation as well in the future