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.
When a form element has an error set, it needs the has-error
class set in order to receive the proper styling.
Code in templates/system/form-element.func.php
does not evaluate the existence of an error properly when no message is set on the error that corresponds to the form element, because the message (an empty string) evaluates to FALSE in the following code:
if ((isset($element['#parents']) && form_get_error($element)) || (!empty($element['#required']) && bootstrap_setting('forms_required_has_error'))) {
$wrapper_attributes['class'][] = 'has-error';
}
This scenario happens frequently when validation logic creates an error which is applicable to multiple form elements.
Comment | File | Size | Author |
---|---|---|---|
#2 | bootstrap-form_item_error_class-2801475-2.patch | 708 bytes | kerasai |
Comments
Comment #2
kerasai CreditAttribution: kerasai at Breakthrough Technologies, LLC commentedThe attached patch tweaks the conditional.
When an error is set with a message,
form_get_error()
returns the message, the conditional evaluates toTRUE
and the code is ran.When an "empty" error is set,
form_get_error()
returns an empty string, the conditional evaluates toTRUE
and the code is ran.When no error is set,
form_get_error()
returns nothing (NULL
), the conditional evaluates toFALSE
and the code not ran.Comment #3
kerasai CreditAttribution: kerasai at Breakthrough Technologies, LLC commentedComment #5
markhalliwell