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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kerasai created an issue. See original summary.

kerasai’s picture

Status: Active » Needs review
FileSize
708 bytes

The attached patch tweaks the conditional.

When an error is set with a message, form_get_error() returns the message, the conditional evaluates to TRUE and the code is ran.

When an "empty" error is set, form_get_error() returns an empty string, the conditional evaluates to TRUE and the code is ran.

When no error is set, form_get_error() returns nothing (NULL), the conditional evaluates to FALSE and the code not ran.

kerasai’s picture

Issue summary: View changes

  • markcarver committed 97d961f on 7.x-3.x authored by kerasai
    Issue #2801475 by kerasai: Form Errors Not Styled As "Has Error" When no...
markhalliwell’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.