Skip to content
Snippets Groups Projects
Commit 3b944f55 authored by Syd's avatar Syd
Browse files

Add form element required indicator (asterisk)

parent 201ef2a7
Branches 9.0.x
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<legend {{ legend.attributes.addClass('mb-3') }}> <legend {{ legend.attributes.addClass('mb-3') }}>
<label{{legend_span.attributes.addClass(legend_span_classes)}}>{{ legend.title }}</label> <label{{legend_span.attributes.addClass(legend_span_classes)}}>{{ legend.title }}</label>
{%- if required and title_display == 'before' -%} {%- if required and title_display == 'before' -%}
<span class="font-weight-bolder form-required--indicator ps-1 text-danger">*</span> <span class="font-weight-bolder text-danger">*</span>
{%- endif -%} {%- endif -%}
</legend> </legend>
{% endif %} {% endif %}
......
...@@ -5,5 +5,8 @@ description: Form Element ...@@ -5,5 +5,8 @@ description: Form Element
props: props:
type: object type: object
properties: properties:
show_required_indicator:
type: boolean
default: true
form_element_attributes: form_element_attributes:
type: Drupal\Core\Template\Attribute type: Drupal\Core\Template\Attribute
...@@ -73,10 +73,15 @@ ...@@ -73,10 +73,15 @@
%} %}
{% set form_element_attributes = form_element_attributes ?: create_attribute() %} {% set form_element_attributes = form_element_attributes ?: create_attribute() %}
{% set show_required_indicator = show_required_indicator|default(true) %}
<div{{ form_element_attributes.addClass(form_element_classes) }}> <div{{ form_element_attributes.addClass(form_element_classes) }}>
{% if label_display in ['before', 'invisible'] %} {% if label_display in ['before', 'invisible'] %}
{{ label }} {{ label }}
{% if element["#required"] and show_required_indicator %}
<span class="font-weight-bolder text-danger">*</span>
{%- endif -%}
{% endif %} {% endif %}
{% if (prefix is not empty) or (suffix is not empty) %} {% if (prefix is not empty) or (suffix is not empty) %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment