Currently theme_checkboxes() and theme_radios() do not make use of _form_set_class() like other form elements, so they do not receive error classes or required classes as necessary. As these elements may be required, these classes are needed in order to visibly style the error'd group just like other form elements are.

Comments

Moonshine’s picture

Assigned: Unassigned » Moonshine
Category: feature » bug
Priority: Normal » Minor
Status: Active » Needs review

Actually I'll mark this as a minor bug, as it does seem to be an inconsistancy in the form validation UI.

dpearcefl’s picture

Status: Needs review » Postponed (maintainer needs more info)

Does this issue exist in current D6?

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Active
kndr’s picture

Version: 6.3 » 6.22
Priority: Minor » Normal
Status: Active » Reviewed & tested by the community

Patch works. I can confirm this bug. Implications are deep and I've wasted couple of hours because of this bug. Finally I've made exactly the same patch. It is pity that I didn't find this issue earlier. I am using Vertical Tabs and this bug causes me big problem with tabs, which should be activated when some of their elements didn't pass validation. Look at #1108574: "required indicator" dont show when CCK-TextField is "Checkboxes/radio buttons"? Class 'error' should be added to checkboxes and radios element too since property #required is set for this elements. Look at function optionwidgets_buttons_process inside optionwidgets module: http://drupalcontrib.org/api/drupal/contributions--cck--modules--optionw... Property #required is set for checkboxes. It is obvious, that element checkboxes should be selected as invalid (with class 'error') when validation fails. Without this patch we have inconsistent behavior and other modules (like Vertical Tabs) has no chance to work properly.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal-6-3-form-error-classes-v1.patch, failed testing.

Everett Zufelt’s picture

Status: Needs work » Needs review
Everett Zufelt’s picture

Version: 6.22 » 6.x-dev

Status: Needs review » Needs work

The last submitted patch, drupal-6-3-form-error-classes-v1.patch, failed testing.

kndr’s picture

One notice. If you don't want to patch the core you could use theme functions inside template.php of YOUR_THEME


function YOUR_THEME_checkboxes($element) {
  _form_set_class($element, array('form-checkboxes'));
  $element['#children'] = '<div '. drupal_attributes($element['#attributes']) .'">'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
  if ($element['#title'] || $element['#description']) {
    unset($element['#id']);
    return theme('form_element', $element, $element['#children']);
  }
  else {
    return $element['#children'];
  }
}

function YOUR_THEME_radios($element) {
  _form_set_class($element, array('form-radios'));
  $element['#children'] = '<div '. drupal_attributes($element['#attributes']) .'">'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
  if ($element['#title'] || $element['#description']) {
    unset($element['#id']);
    return theme('form_element', $element, $element['#children']);
  }
  else {
    return $element['#children'];
  }
}

Moonshine’s picture

Version: 6.x-dev » 7.x-dev

Wow, this is still present in D7. :( If I cook up a new patch is there a chance to get it in a maintenance release?

jackbravo’s picture

Status: Needs work » Closed (duplicate)

This would be the patch for D7. But it also needs theming changes so I wouldn't applied it as is. system.messages.css which contains this line:

div.error {
  background-image: url(../../misc/message-24-error.png);
  border-color: #ed541d;
}
<code>

The diff is as follows:

<code>
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2822,7 +2822,7 @@ function theme_radios($variables) {
   if (isset($element['#id'])) {
     $attributes['id'] = $element['#id'];
   }
-  $attributes['class'] = 'form-radios';
+  _form_set_class($element, array('form-radios'));
   if (!empty($element['#attributes']['class'])) {
     $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']);
   }

Also, this seems to be a duplicate of #222380: No error highlighting on form checkbox or radio input types. So I think this should be closed instead anyway =P.