Skip to content

Commit b38c730

Browse files
committed
Fix required checkbox rendering so label gets proper styles, add hook_preprocess_form_element to set required market for twig
1 parent 9a0838e commit b38c730

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

templates/input/form-element-label.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
title_display == 'invisible' and not (is_checkbox or is_radio) ? 'sr-only',
2626
required ? 'js-form-required',
2727
required ? 'form-required',
28-
required ? 'required'
28+
required and not (is_checkbox or is_radio) ? 'required'
2929
]
3030
-%}
3131
{% if title is not empty and title_display == 'invisible' and (is_checkbox or is_radio) -%}

templates/input/form-element.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
is_radio ? 'radio',
6262
is_checkbox ? 'checkbox',
6363
is_autocomplete ? 'form-autocomplete',
64-
has_error ? 'error has-error'
64+
has_error ? 'error has-error',
65+
required ? 'required',
6566
]
6667
%}{%
6768
set description_classes = [

wxt_bootstrap.theme

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,12 @@ function wxt_bootstrap_preprocess_paragraph(&$variables) {
338338
$variables['link_provider_label'] = $allowed_values[$key] ?? $key;
339339
}
340340
}
341+
342+
/**
343+
* Implements hook_preprocess_form_element().
344+
*/
345+
function wxt_bootstrap_preprocess_form_element(array &$variables) {
346+
if (!empty($variables['element']['#required'])) {
347+
$variables['required'] = TRUE;
348+
}
349+
}

0 commit comments

Comments
 (0)