Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Drupal converts a radios element to multiple radio inside a fieldset.
The title is extended with the required property and passed into the fieldset label.
The fieldset then however ignores the required property.
See web/core/modules/system/templates/fieldset.html.twig
Thus the asterisk indicating required is missing.
Proposed resolution
Support required indication through the usual markup in fieldset labels.
This will fix all composite form elements (Radios, Checkboxes).
The usual markup is:
See web/themes/contrib/bs_base/themes/bs_bootstrap/templates/form/form-element-label.html.twig
<label{{ attributes.addClass(classes) }}>{{ title }}{% if required %}<span class="form-required-mark"></span>{% endif %}</label>
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#2 | radios-fieldsets-details-missing-require-mark-3015068-2.patch | 2.25 KB | pivica |
#2 | Selection_297.png | 64.63 KB | pivica |
#2 | Selection_298.png | 53 KB | pivica |
Comments
Comment #2
pivica CreditAttribution: pivica at MD Systems GmbH commentedActually logic for required fieldset existed, but it was not updated after https://cgit.drupalcode.org/bs_base/commit/?id=e9785a3 which added new span.form-required-mark element because previous require::after pseudo element were conflicting with Bootstrap custom form elements.
I've added span.form-required-mark to fieldset and details twig templates. Also added detection when form_group inserts required-fields CSS class in attributes - now we switch required flag to true.
Created example form and tested it against seven, looks good now:
Seven screenshot:
BS Bootstrap screenshot:
Comment #3
pivica CreditAttribution: pivica at MD Systems GmbH commentedComment #5
pivica CreditAttribution: pivica at MD Systems GmbH commentedCommitted.