Issue #1540174 by Niklas Fiekas, attiks: Fixed Some attributes not allowed for the new HTML5 input elements.

8.0.x
catch 2012-05-08 11:53:23 +09:00
parent fe01ab6e16
commit 3e8861682a
14 changed files with 136 additions and 38 deletions

View File

@ -3951,8 +3951,8 @@ function theme_tel($variables) {
* @param $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #min, #max,
* #placeholder, #required, #attributes, #step.
* Properties used: #title, #value, #description, #min, #max, #placeholder,
* #required, #attributes, #step.
*
* @ingroup themeable
*/
@ -3960,7 +3960,7 @@ function theme_number($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'number';
element_set_attributes($element, array('id', 'name', 'value', 'size', 'step', 'min', 'max', 'maxlength', 'placeholder'));
element_set_attributes($element, array('id', 'name', 'value', 'step', 'min', 'max', 'placeholder'));
_form_set_class($element, array('form-number'));
$output = '<input' . drupal_attributes($element['#attributes']) . ' />';
@ -3974,8 +3974,8 @@ function theme_number($variables) {
* @param $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #min, #max,
* #required, #attributes, #step.
* Properties used: #title, #value, #description, #min, #max, #attributes,
* #step.
*
* @ingroup themeable
*/
@ -4031,6 +4031,36 @@ function form_validate_number(&$element, &$form_state) {
}
}
/**
* Determines the value for a range element.
*
* Make sure range elements always have a value. The 'required' attribute is not
* allowed for range elements.
*
* @param $element
* The form element whose value is being populated.
* @param $input
* The incoming input to populate the form element. If this is FALSE, the
* element's default value should be returned.
*
* @return
* The data that will appear in the $form_state['values'] collection for
* this element. Return nothing to use the default.
*/
function form_type_range_value($element, $input = FALSE) {
if ($input === '') {
$offset = ($element['#max'] - $element['#min']) / 2;
// Round to the step.
if (strtolower($element['#step']) != 'any') {
$steps = round($offset / $element['#step']);
$offset = $element['#step'] * $steps;
}
return $element['#min'] + $offset;
}
}
/**
* Returns HTML for a url form element.
*

View File

@ -324,11 +324,6 @@ function number_field_widget_form(&$form, &$form_state, $field, $instance, $lang
$element += array(
'#type' => 'number',
'#default_value' => $value,
// Allow a slightly larger size that the field length to allow for some
// configurations where all characters won't fit in input field.
'#size' => $field['type'] == 'number_decimal' ? $field['settings']['precision'] + 4 : 12,
// Allow two extra characters for signed values and decimal separator.
'#maxlength' => $field['type'] == 'number_decimal' ? $field['settings']['precision'] + 2 : 10,
);
// Set the step for floating point and decimal numbers.

View File

@ -225,7 +225,6 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form
$element['trim_length'] = array(
'#title' => t('Trim length'),
'#type' => 'number',
'#size' => 10,
'#default_value' => $settings['trim_length'],
'#min' => 1,
'#required' => TRUE,

View File

@ -158,7 +158,6 @@ function hook_field_formatter_settings_form($field, $instance, $view_mode, $form
$element['trim_length'] = array(
'#title' => t('Length'),
'#type' => 'number',
'#size' => 20,
'#default_value' => $settings['trim_length'],
'#min' => 1,
'#required' => TRUE,

View File

@ -1363,8 +1363,6 @@ function _filter_url_settings($form, &$form_state, $filter, $format, $defaults)
'#type' => 'number',
'#title' => t('Maximum link text length'),
'#default_value' => $filter->settings['filter_url_length'],
'#size' => 5,
'#maxlength' => 4,
'#min' => 1,
'#field_suffix' => t('characters'),
'#description' => t('URLs longer than this number of characters will be truncated to prevent long strings that break formatting. The link itself will be retained; just the text portion of the link will be truncated.'),

View File

@ -450,7 +450,6 @@ function image_resize_form($data) {
'#default_value' => isset($data['width']) ? $data['width'] : '',
'#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE,
'#size' => 10,
'#min' => 1,
);
$form['height'] = array(
@ -459,7 +458,6 @@ function image_resize_form($data) {
'#default_value' => isset($data['height']) ? $data['height'] : '',
'#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE,
'#size' => 10,
'#min' => 1,
);
return $form;
@ -547,8 +545,6 @@ function image_rotate_form($data) {
'#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),
'#field_suffix' => '&deg;',
'#required' => TRUE,
'#size' => 6,
'#maxlength' => 4,
);
$form['bgcolor'] = array(
'#type' => 'textfield',

View File

@ -91,8 +91,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Maximum width'),
'#title_display' => 'invisible',
'#default_value' => $max_resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' x ',
);
@ -101,8 +99,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Maximum height'),
'#title_display' => 'invisible',
'#default_value' => $max_resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' ' . t('pixels'),
);
@ -122,8 +118,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Minimum width'),
'#title_display' => 'invisible',
'#default_value' => $min_resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' x ',
);
@ -132,8 +126,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Minimum height'),
'#title_display' => 'invisible',
'#default_value' => $min_resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' ' . t('pixels'),
);

View File

@ -389,8 +389,6 @@ function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight
'#title' => $value !== '' ? t('Vote count for choice @label', array('@label' => $value)) : t('Vote count for new choice'),
'#title_display' => 'invisible',
'#default_value' => $votes,
'#size' => 5,
'#maxlength' => 7,
'#min' => 0,
'#parents' => array('choice', $key, 'chvotes'),
'#access' => user_access('administer nodes'),

View File

@ -93,9 +93,8 @@ function search_admin_settings($form) {
'#type' => 'number',
'#title' => t('Minimum word length to index'),
'#default_value' => variable_get('minimum_word_size', 3),
'#size' => 5,
'#maxlength' => 3,
'#min' => 1,
'#max' => 1000,
'#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).')
);
$form['indexing_settings']['overlap_cjk'] = array(

View File

@ -23,8 +23,6 @@ function image_gd_settings() {
'#type' => 'number',
'#title' => t('JPEG quality'),
'#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'),
'#size' => 10,
'#maxlength' => 3,
'#min' => 0,
'#max' => 100,
'#default_value' => variable_get('image_jpeg_quality', 75),

View File

@ -405,9 +405,7 @@ function system_element_info() {
);
$types['number'] = array(
'#input' => TRUE,
'#size' => 30,
'#step' => 1,
'#maxlength' => 128,
'#process' => array('ajax_process_form'),
'#element_validate' => array('form_validate_number'),
'#theme' => 'number',
@ -415,11 +413,9 @@ function system_element_info() {
);
$types['range'] = array(
'#input' => TRUE,
'#size' => 30,
'#step' => 1,
'#min' => 0,
'#max' => 100,
'#maxlength' => 128,
'#process' => array('ajax_process_form'),
'#element_validate' => array('form_validate_number'),
'#theme' => 'range',

View File

@ -365,6 +365,20 @@ class FormsTestCase extends DrupalWebTestCase {
}
}
/**
* Tests default value handling of #type 'range' elements.
*/
function testRange() {
$values = json_decode($this->drupalPost('form-test/range', array(), 'Submit'));
$this->assertEqual($values->with_default_value, 18);
$this->assertEqual($values->float, 10.5);
$this->assertEqual($values->integer, 6);
$this->assertEqual($values->offset, 6.9);
$this->drupalPost('form-test/range/invalid', array(), 'Submit');
$this->assertFieldByXPath('//input[@type="range" and contains(@class, "error")]', NULL, 'Range element has the error class.');
}
/**
* Test handling of disabled elements.
*

View File

@ -145,6 +145,18 @@ function form_test_menu() {
'page arguments' => array('form_test_number', 'range'),
'access callback' => TRUE,
);
$items['form-test/range']= array(
'title' => 'Range',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_range'),
'access callback' => TRUE,
);
$items['form-test/range/invalid'] = array(
'title' => 'Invalid range',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_range_invalid'),
'access callback' => TRUE,
);
$items['form-test/checkboxes-radios'] = array(
'title' => t('Checkboxes, Radios'),
'page callback' => 'drupal_get_form',
@ -1276,6 +1288,80 @@ function form_test_number($form, &$form_state, $element = 'number') {
return $form;
}
/**
* Form constructor for testing #type 'range' elements.
*
* @see form_test_range_submit()
* @ingroup forms
*/
function form_test_range($form, &$form_state) {
$form['with_default_value'] = array(
'#type' => 'range',
'#title' => 'Range with default value',
'#min' => 10,
'#max' => 20,
'#step' => 2,
'#default_value' => 18,
'#description' => 'The default value is 18.',
);
$form['float'] = array(
'#type' => 'range',
'#title' => 'Float',
'#min' => 10,
'#max' => 11,
'#step' => 'any',
'#description' => 'Floating point number between 10 and 11.',
);
$form['integer'] = array(
'#type' => 'range',
'#title' => 'Integer',
'#min' => 2,
'#max' => 8,
'#step' => 2,
'#description' => 'Even integer between 2 and 8.',
);
$form['offset'] = array(
'#type' => 'range',
'#title' => 'Offset',
'#min' => 2.9,
'#max' => 10.9,
'#description' => 'Value between 2.9 and 10.9.',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
/**
* Form submission handler for form_test_range().
*/
function form_test_range_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
exit;
}
/**
* Form constructor for testing invalid #type 'range' elements.
*
* @ingroup forms
*/
function form_test_range_invalid($form, &$form_state) {
$form['minmax'] = array(
'#type' => 'range',
'#min' => 10,
'#max' => 5,
'#title' => 'Invalid range',
'#description' => 'Minimum greater than maximum.',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
/**
* Builds a form to test the placeholder attribute.
*/

View File

@ -404,8 +404,6 @@ function user_admin_settings() {
'#type' => 'number',
'#title' => t('Picture upload file size'),
'#default_value' => variable_get('user_picture_file_size', '30'),
'#size' => 10,
'#maxlength' => 10,
'#min' => 0,
'#field_suffix' => ' ' . t('KB'),
'#description' => t('Maximum allowed file size for uploaded pictures. Upload size is normally limited only by the PHP maximum post and file upload settings, and images are automatically scaled down to the dimensions specified above.'),