Commit 35c4ad2b authored by Gerhard Killesreiter's avatar Gerhard Killesreiter

#54104, CSS classes broken on all form elements, patch by Nedjo

parent a81547d5
...@@ -557,7 +557,8 @@ function form_options_flatten($array, $reset = TRUE) { ...@@ -557,7 +557,8 @@ function form_options_flatten($array, $reset = TRUE) {
function theme_select($element) { function theme_select($element) {
$select = ''; $select = '';
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : ''; $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
return theme('form_element', $element['#title'], '<select class="' . _form_get_class('', $element['#required'], form_get_error($element)). '" name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size .'>'. form_select_options($element) .'</select>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); _form_set_class($element);
return theme('form_element', $element['#title'], '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size .'>'. form_select_options($element) .'</select>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
} }
function form_select_options($element, $choices = NULL) { function form_select_options($element, $choices = NULL) {
...@@ -622,8 +623,8 @@ function theme_fieldset($element) { ...@@ -622,8 +623,8 @@ function theme_fieldset($element) {
* A themed HTML string representing the form item group. * A themed HTML string representing the form item group.
*/ */
function theme_radio($element) { function theme_radio($element) {
_form_set_class($element, array('form-radio'));
$output = '<input type="radio" '; $output = '<input type="radio" ';
$output .= 'class="'. _form_get_class('form-radio', $element['#required'], form_get_error($element)) .'" ';
$output .= 'name="' . $element['#name'] .'" '; $output .= 'name="' . $element['#name'] .'" ';
$output .= 'value="'. $element['#return_value'] .'" '; $output .= 'value="'. $element['#return_value'] .'" ';
$output .= ($element['#value'] == $element['#return_value']) ? ' checked="checked" ' : ' '; $output .= ($element['#value'] == $element['#return_value']) ? ' checked="checked" ' : ' ';
...@@ -817,9 +818,9 @@ function theme_item($element) { ...@@ -817,9 +818,9 @@ function theme_item($element) {
* A themed HTML string representing the checkbox. * A themed HTML string representing the checkbox.
*/ */
function theme_checkbox($element) { function theme_checkbox($element) {
_form_set_class($element, array('form-checkbox'));
$checkbox = '<input '; $checkbox = '<input ';
$checkbox .= 'type="checkbox" '; $checkbox .= 'type="checkbox" ';
$checkbox .= 'class="'. _form_get_class('form-checkbox', $element['#required'], form_get_error($element)) . '" ';
$checkbox .= 'name="'. $element['#name'] .'" '; $checkbox .= 'name="'. $element['#name'] .'" ';
$checkbox .= 'id="'. $element['#id'].'" ' ; $checkbox .= 'id="'. $element['#id'].'" ' ;
$checkbox .= 'value="'. $element['#return_value'] .'" '; $checkbox .= 'value="'. $element['#return_value'] .'" ';
...@@ -906,15 +907,15 @@ function theme_hidden($element) { ...@@ -906,15 +907,15 @@ function theme_hidden($element) {
*/ */
function theme_textfield($element) { function theme_textfield($element) {
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : ''; $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
$class = ''; $class = array('form-text');
$extra = ''; $extra = '';
if ($element['#autocomplete_path']) { if ($element['#autocomplete_path']) {
drupal_add_js('misc/autocomplete.js'); drupal_add_js('misc/autocomplete.js');
$class = ' form-autocomplete'; $class[] = 'form-autocomplete';
$extra = '<input class="autocomplete" type="hidden" id="'. $element['#id'] .'-autocomplete" value="'. check_url(url($element['#autocomplete_path'], NULL, NULL, TRUE)) .'" disabled="disabled" />'; $extra = '<input class="autocomplete" type="hidden" id="'. $element['#id'] .'-autocomplete" value="'. check_url(url($element['#autocomplete_path'], NULL, NULL, TRUE)) .'" disabled="disabled" />';
} }
_form_set_class($element, $class);
$output = '<input type="text" maxlength="'. $element['#maxlength'] .'" class="'. _form_get_class("form-text$class", $element['#required'], form_get_error($element)) .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />'; $output = '<input type="text" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)). $extra; return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)). $extra;
} }
...@@ -943,15 +944,15 @@ function theme_form($element) { ...@@ -943,15 +944,15 @@ function theme_form($element) {
* A themed HTML string representing the textarea. * A themed HTML string representing the textarea.
*/ */
function theme_textarea($element) { function theme_textarea($element) {
$class = 'textarea'; $class = array('textarea');
if ($element['#resizable'] !== false) { if ($element['#resizable'] !== false) {
drupal_add_js('misc/textarea.js'); drupal_add_js('misc/textarea.js');
$class .= ' resizable'; $class[] = 'resizable';
} }
$cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : ''; $cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : '';
_form_set_class($element, $class);
return theme('form_element', $element['#title'], '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" class="'. _form_get_class($class, $element['#required'], form_get_error($element)) .'"'. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); return theme('form_element', $element['#title'], '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
} }
/** /**
...@@ -982,7 +983,8 @@ function theme_markup($element) { ...@@ -982,7 +983,8 @@ function theme_markup($element) {
function theme_password($element) { function theme_password($element) {
$size = $element['#size'] ? ' size="'. $element['#size'] .'" ' : ''; $size = $element['#size'] ? ' size="'. $element['#size'] .'" ' : '';
$output = '<input type="password" maxlength="'. $element['#maxlength'] .'" class="'. _form_get_class('form-text', $element['#required'], form_get_error($element)) .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size . drupal_attributes($element['#attributes']) .' />'; _form_set_class($element, array('form-text'));
$output = '<input type="password" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size . drupal_attributes($element['#attributes']) .' />';
return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
} }
...@@ -1026,11 +1028,31 @@ function theme_weight($element) { ...@@ -1026,11 +1028,31 @@ function theme_weight($element) {
* provided by file.inc. * provided by file.inc.
*/ */
function theme_file($element) { function theme_file($element) {
return theme('form_element', $element['#title'], '<input type="file" class="'. _form_get_class('form-file', $element['#required'], form_get_error($element)) .'" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. form_clean_id($element['#id']) .'" size="'. $element['#size'] ."\" />\n", $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); _form_set_class($element, array('form-file'));
return theme('form_element', $element['#title'], '<input type="file" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. form_clean_id($element['#id']) .'" size="'. $element['#size'] ."\" />\n", $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
} }
function _form_get_class($name, $required, $error) { /**
return $name. ($required ? ' required' : '') . (isset($error) ? ' error' : ''); * Sets a form element's class attribute.
*
* Adds 'required' and 'error' classes as needed.
*
* @param &$element
* The form element
* @param $name
* Array of new class names to be added
*/
function _form_set_class(&$element, $class = array()) {
if ($element['#required']) {
$class[] = 'required';
}
if (form_get_error($element)){
$class[] = 'error';
}
if (isset($element['#attributes']['class'])) {
$class[] = $element['#attributes']['class'];
}
$element['#attributes']['class'] = implode(' ', $class);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment