I'm using Twitter Bootstrap and I want to expand the length of all the title fields in the content forms by adding 'span6' to the class attribute for the title field's input element.
I've added the following function to my template.php file:
function ccom_field__title($variables) {
$output = '';
// Render the label, if it's not hidden.
if (!$variables['label_hidden']) {
$output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ': </div>';
}
// Render the items.
$output .= '<div class="field-items"' . $variables['content_attributes'] . '>';
foreach ($variables['items'] as $delta => $item) {
$classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');
$output .= '<div class="' . $classes . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</div>';
}
$output .= '</div>';
// Render the top-level DIV.
$output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';
return $output;
}
Right now all I've done to it is change the name of the function according to the functions preceding comment. I'm not sure what I need to do, because I need to add the class to the input element directly, and not its parent div element.
Using JavaScript (including jQuery) is not an option.
TL;DR
How does one add a class to a specific field's input element?
field_title
that you want to add the class to, or do you mean the normal title? – Clive♦ Apr 19 '12 at 23:11hook_form_alter()
, I'll pop an answer in – Clive♦ Apr 19 '12 at 23:30