Problem/Motivation
The "Flag as required" option is shown even when the Name field is not required. This is confusing because an optional field must not be HTML5 required.
Steps to reproduce
- Create a Name field.
- Get to the field settings form.
- Uncheck the box to make this field not required.
- Observe that the "Flag as required" checkbox is still available.
Proposed resolution
While unrelated to #3559064: Fix minimum components required markers shown when the base field is optional, it was initially captured there as a good followup and has a related #3559436: Hide “Show required marker” checkbox when Name field is not required.
Minimum components are only to be HTML5 required when the Name field itself is required, therefore we should only display the "Flag as required" checkbox when the Name field itself is configured as required.
We can use #states to conditionally show or hide the field settings checkbox based on the field required setting.
Remaining tasks
- Update component configuration form to apply conditional visibility.
- Add or update test coverage.
User interface changes
Component "Flag as required" options are only visible when the Name field is required.


API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | name-revert-hide-flag-as-required-3559437-15.patch | 5.22 KB | jcandan |
Issue fork name-3559437
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jcandan commentedI kept this separate from #3559436: Hide “Show required marker” checkbox when Name field is not required because this is something that can be adopted immediately. While that other ticket is awaiting #3559064: Fix minimum components required markers shown when the base field is optional before it would make sense to go forward with it. This ticket is unblocked. That ticket is blocked.
Comment #3
aryan singh commentedWorking...
Comment #5
aryan singh commentedI have raised a MR and I have checked it locally it is working fine.
Comment #8
bluegeek9 commentedComment #9
bluegeek9 commentedComment #13
jcandan commentedCrap. I just stepped on my own toes.
This now prevents
#statesfrom marking a conditionally required Name field's component fields, because a site-builder would have to mark the field not-required so that it can be conditionally required at runtime.It's an interesting problem. Core doesn't give you the option to supply the
required="required"attribute--it just does it. Name provides the option, so it makes sense to take away that option when the field is not required.But, that means it also makes sense to take away the option to choose whether to show required markers on component fields when the field is not required. But, without that, subsequent conditions (e.g. Conditional Fields, Require on Publish) now have to assume that choice (whether to mark component fields required). Which should subsequent handlers choose? Conditional Fields doesn't implement such field-specific changes. Require on Publish was forced to because it is doing something special with requiredness. But, this would be true for any such
#statesimplementations.Should Name continue to provide these optional required UI handlers despite core's assumption? If so, do we expose these options even when the field is not required in field settings? Perhaps we can with help text noting that it only applies if/when required (whether marked above or via
#stateschanges at runtime).Having thought through the above, I think that last option makes the most sense. Revert this change, and adopt a help text that notes applicability.
Comment #14
jcandan commentedOh, it's even worse than I thought. The field settings option to show required markers already had that conditional help text!:
I feel stupid.
Okay, but, the Flag option which places the
required="requiredattribute could probably be improved.How about...?
Comment #15
jcandan commentedComment #17
jcandan commented@bluegeek9, would you prefer I open a new issue to discuss and revert this?
Comment #18
bluegeek9 commentedI need to review this.
Comment #19
alan d. commentedFrom memory, this was originally just a user facing UI feature to indicate parts of the name were required. For example, given and family were both required for a valid name albeit the name field itself was optional.
Is this feature broken now? At least one other issue that seems to have been committed without understanding what this was for...
I'm unsure if that feature was carried into the original D8 port and if it was covered by the ported tests, but it sounds like it may need a quick review to see if it's still working. It's purely decorative! It should have never directly added the standard browser validation to a fully empty field, blocking the parent form submission when empty!
This was effectively what it did do in Drupal 7, basically an asterisk with some title text explaining why there was an asterisk.
The Drupal 7 admin text was "'Appends an asterisk after the component title if the component is required as part of a complete name.'".
As an aside, I remember prototyping various front end options to indicate this to the field itself, but most just cluttered the form / made it more confusing. It's possible this does make some users unnecessarily type in something into the name field, but it was never raised as an issue prior to 2018 and there was a built-in way to indirectly modify this with a variable override (no admin UI though) and the theming function itself.
Edit: re-reading this, this could apply to a new feature? I decided against additional custom validation back in the day as it would definitely need custom client side jscript validation to be implemented correctly.
Comment #22
bluegeek9 commentedI reverted the changes.