From 699afdd1be4b8034c36474c7191972604bf5f54e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 31 Jul 2010 04:01:51 +0000 Subject: - Patch #690980 by seutje, sun, seanyo, aaroncouch: disabled form elements not properly rendered. --- includes/form.inc | 171 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 117 insertions(+), 54 deletions(-) (limited to 'includes') diff --git a/includes/form.inc b/includes/form.inc index 28b94b65e..c5525c9e2 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -2368,15 +2368,16 @@ function theme_fieldset($variables) { */ function theme_radio($variables) { $element = $variables['element']; + $element['#attributes']['type'] = 'radio'; + $element['#attributes']['name'] = $element['#name']; + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['value'] = $element['#return_value']; + if (check_plain($element['#value']) == $element['#return_value']) { + $element['#attributes']['checked'] = 'checked'; + } _form_set_class($element, array('form-radio')); - $output = ''; - return $output; + return ''; } /** @@ -2602,19 +2603,17 @@ function form_process_radios($element) { function theme_checkbox($variables) { $element = $variables['element']; $t = get_t(); - _form_set_class($element, array('form-checkbox')); - $checkbox = ''; + _form_set_class($element, array('form-checkbox')); - return $checkbox; + return ''; } /** @@ -3057,9 +3056,18 @@ function theme_submit($variables) { */ function theme_button($variables) { $element = $variables['element']; + $element['#attributes']['type'] = 'submit'; + if (!empty($element['#name'])) { + $element['#attributes']['name'] = $element['#name']; + } + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['value'] = $element['#value']; $element['#attributes']['class'][] = 'form-' . $element['#button_type']; + if (!empty($element['#attributes']['disabled'])) { + $element['#attributes']['class'][] = 'form-button-disabled'; + } - return '\n"; + return ''; } /** @@ -3074,15 +3082,24 @@ function theme_button($variables) { */ function theme_image_button($variables) { $element = $variables['element']; + $element['#attributes']['type'] = 'submit'; + $element['#attributes']['name'] = $element['#name']; + if (!empty($element['#value'])) { + $element['#attributes']['value'] = $element['#value']; + } + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['src'] = file_create_url($element['#src']); + if (!empty($element['#title'])) { + $element['#attributes']['alt'] = $element['#title']; + $element['#attributes']['title'] = $element['#title']; + } + $element['#attributes']['class'][] = 'form-' . $element['#button_type']; + if (!empty($element['#attributes']['disabled'])) { + $element['#attributes']['class'][] = 'form-button-disabled'; + } - return '\n"; + return ''; } /** @@ -3097,7 +3114,11 @@ function theme_image_button($variables) { */ function theme_hidden($variables) { $element = $variables['element']; - return '\n"; + $element['#attributes']['type'] = 'hidden'; + $element['#attributes']['name'] = $element['#name']; + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['value'] = $element['#value']; + return '\n"; } /** @@ -3113,20 +3134,33 @@ function theme_hidden($variables) { */ function theme_textfield($variables) { $element = $variables['element']; - $size = empty($element['#size']) ? '' : ' size="' . $element['#size'] . '"'; - $maxlength = empty($element['#maxlength']) ? '' : ' maxlength="' . $element['#maxlength'] . '"'; - $class = array('form-text'); - $extra = ''; - $output = ''; + $element['#attributes']['type'] = 'text'; + $element['#attributes']['name'] = $element['#name']; + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['value'] = $element['#value']; + if (!empty($element['#size'])) { + $element['#attributes']['size'] = $element['#size']; + } + if (!empty($element['#maxlength'])) { + $element['#attributes']['maxlength'] = $element['#maxlength']; + } + _form_set_class($element, array('form-text')); + $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_js('misc/autocomplete.js'); - $class[] = 'form-autocomplete'; - $extra = ''; + $element['#attributes']['class'][] = 'form-autocomplete'; + + $attributes = array(); + $attributes['type'] = 'hidden'; + $attributes['id'] = $element['#id'] . '-autocomplete'; + $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); + $attributes['disabled'] = 'disabled'; + $attributes['class'][] = 'autocomplete'; + $extra = ''; } - _form_set_class($element, $class); - $output .= ''; + $output = ''; return $output . $extra; } @@ -3143,14 +3177,16 @@ function theme_textfield($variables) { */ function theme_form($variables) { $element = $variables['element']; - // Anonymous div to satisfy XHTML compliance. - $action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : ''; - + if (!empty($element['#action'])) { + $element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']); + } + $element['#attributes']['method'] = $element['#method']; if (empty($element['#attributes']['accept-charset'])) { $element['#attributes']['accept-charset'] = "UTF-8"; } - - return '
\n
". $element['#children'] ."\n
\n"; + $element['#attributes']['id'] = $element['#id']; + // Anonymous DIV to satisfy XHTML compliance. + return '
' . $element['#children'] . '
'; } /** @@ -3166,10 +3202,16 @@ function theme_form($variables) { */ function theme_textarea($variables) { $element = $variables['element']; + $element['#attributes']['name'] = $element['#name']; + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['value'] = $element['#value']; + $element['#attributes']['cols'] = $element['#cols']; + $element['#attributes']['rows'] = $element['#rows']; + _form_set_class($element, array('form-textarea')); + $wrapper_attributes = array( 'class' => array('form-textarea-wrapper'), ); - $class = array('form-textarea'); // Add resizable behavior. if (!empty($element['#resizable'])) { @@ -3178,10 +3220,7 @@ function theme_textarea($variables) { } $output = ''; - - _form_set_class($element, $class); - $output .= ''; - + $output .= '' . check_plain($element['#value']) . ''; $output .= ''; return $output; } @@ -3199,12 +3238,19 @@ function theme_textarea($variables) { */ function theme_password($variables) { $element = $variables['element']; - $size = $element['#size'] ? ' size="' . $element['#size'] . '" ' : ''; - $maxlength = $element['#maxlength'] ? ' maxlength="' . $element['#maxlength'] . '" ' : ''; - + $element['#attributes']['type'] = 'password'; + $element['#attributes']['name'] = $element['#name']; + $element['#attributes']['id'] = $element['#id']; + $element['#attributes']['value'] = $element['#value']; + if (!empty($element['#size'])) { + $element['#attributes']['size'] = $element['#size']; + } + if (!empty($element['#maxlength'])) { + $element['#attributes']['maxlength'] = $element['#maxlength']; + } _form_set_class($element, array('form-text')); - $output = ''; - return $output; + + return ''; } /** @@ -3237,17 +3283,30 @@ function form_process_weight($element) { */ function theme_file($variables) { $element = $variables['element']; + $element['#attributes']['type'] = 'file'; + $element['#attributes']['name'] = $element['#name']; + $element['#attributes']['id'] = $element['#id']; + if (!empty($element['#size'])) { + $element['#attributes']['size'] = $element['#size']; + } _form_set_class($element, array('form-file')); - return '\n"; + + return ''; } /** * Returns HTML for a form element. * - * Each form element is wrapped in a DIV with #type and #name classes. In - * addition to the element itself, the div contains a label before or after - * the element based on the optional #title_display property. After the label - * and fields this function outputs the optional element #description. + * Each form element is wrapped in a DIV container having the following CSS + * classes: + * - form-item: Generic for all form elements. + * - form-type-#type: The internal element #type. + * - form-item-#name: The internal form element #name (usually derived from the + * $form structure and set via form_builder()). + * - form-disabled: Only set if the form element is #disabled. + * + * In addition to the element itself, the DIV contains a label for the element + * based on the optional #title_display property, and an optional #description. * * The optional #title_display property can have these values: * - before: The label is output before the element. This is the default. @@ -3298,6 +3357,10 @@ function theme_form_element($variables) { if (!empty($element['#name'])) { $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); } + // Add a class for disabled elements to facilitate cross-browser styling. + if (!empty($element['#attributes']['disabled'])) { + $attributes['class'][] = 'form-disabled'; + } $output = '' . "\n"; // If #title is not set, we don't display any label or required marker. -- cgit v1.2.3