Form item classes

Benjamin Melançon's picture
Submitted by Benjamin Melançon on 2010, December 6 - 13:31

Tags

  • forms
  • Drupal 7 much improves the classes added to the div surrounding form items (in Drupal 6 it was hard-coded to 'form-item'). The type of form element and the form element name are now added as form-item-type and form-item-name. You can see how Drupal does this (and see the theme function you would override to change this) at api.drupal.org/theme_form_element.

    Unfortunately we cannot add custom classes to forms we define or forms we alter, but between the classes based on the type and the name we can generally target the form items with CSS or JavaScript as we need to, without adding another div or other wrapping element or overriding the theme_form_element() function.

  • Explanation

  • This inability to control form element divs is a frustration from Drupal 6, mitigated in 7, and could go in a module building, form altering, or theming section.
  • Book element

  • Note