Commit 3e886168 authored by catch's avatar catch
Browse files

Issue #1540174 by Niklas Fiekas, attiks: Fixed Some attributes not allowed for...

Issue #1540174 by Niklas Fiekas, attiks: Fixed Some attributes not allowed for the new HTML5 input elements.
parent fe01ab6e
...@@ -3951,8 +3951,8 @@ function theme_tel($variables) { ...@@ -3951,8 +3951,8 @@ function theme_tel($variables) {
* @param $variables * @param $variables
* An associative array containing: * An associative array containing:
* - element: An associative array containing the properties of the element. * - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #min, #max, * Properties used: #title, #value, #description, #min, #max, #placeholder,
* #placeholder, #required, #attributes, #step. * #required, #attributes, #step.
* *
* @ingroup themeable * @ingroup themeable
*/ */
...@@ -3960,7 +3960,7 @@ function theme_number($variables) { ...@@ -3960,7 +3960,7 @@ function theme_number($variables) {
$element = $variables['element']; $element = $variables['element'];
$element['#attributes']['type'] = 'number'; $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')); _form_set_class($element, array('form-number'));
$output = '<input' . drupal_attributes($element['#attributes']) . ' />'; $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
...@@ -3974,8 +3974,8 @@ function theme_number($variables) { ...@@ -3974,8 +3974,8 @@ function theme_number($variables) {
* @param $variables * @param $variables
* An associative array containing: * An associative array containing:
* - element: An associative array containing the properties of the element. * - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #min, #max, * Properties used: #title, #value, #description, #min, #max, #attributes,
* #required, #attributes, #step. * #step.
* *
* @ingroup themeable * @ingroup themeable
*/ */
...@@ -4031,6 +4031,36 @@ function form_validate_number(&$element, &$form_state) { ...@@ -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. * Returns HTML for a url form element.
* *
......
...@@ -324,11 +324,6 @@ function number_field_widget_form(&$form, &$form_state, $field, $instance, $lang ...@@ -324,11 +324,6 @@ function number_field_widget_form(&$form, &$form_state, $field, $instance, $lang
$element += array( $element += array(
'#type' => 'number', '#type' => 'number',
'#default_value' => $value, '#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. // Set the step for floating point and decimal numbers.
......
...@@ -225,7 +225,6 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form ...@@ -225,7 +225,6 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form
$element['trim_length'] = array( $element['trim_length'] = array(
'#title' => t('Trim length'), '#title' => t('Trim length'),
'#type' => 'number', '#type' => 'number',
'#size' => 10,
'#default_value' => $settings['trim_length'], '#default_value' => $settings['trim_length'],
'#min' => 1, '#min' => 1,
'#required' => TRUE, '#required' => TRUE,
......
...@@ -158,7 +158,6 @@ function hook_field_formatter_settings_form($field, $instance, $view_mode, $form ...@@ -158,7 +158,6 @@ function hook_field_formatter_settings_form($field, $instance, $view_mode, $form
$element['trim_length'] = array( $element['trim_length'] = array(
'#title' => t('Length'), '#title' => t('Length'),
'#type' => 'number', '#type' => 'number',
'#size' => 20,
'#default_value' => $settings['trim_length'], '#default_value' => $settings['trim_length'],
'#min' => 1, '#min' => 1,
'#required' => TRUE, '#required' => TRUE,
......
...@@ -1363,8 +1363,6 @@ function _filter_url_settings($form, &$form_state, $filter, $format, $defaults) ...@@ -1363,8 +1363,6 @@ function _filter_url_settings($form, &$form_state, $filter, $format, $defaults)
'#type' => 'number', '#type' => 'number',
'#title' => t('Maximum link text length'), '#title' => t('Maximum link text length'),
'#default_value' => $filter->settings['filter_url_length'], '#default_value' => $filter->settings['filter_url_length'],
'#size' => 5,
'#maxlength' => 4,
'#min' => 1, '#min' => 1,
'#field_suffix' => t('characters'), '#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.'), '#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.'),
......
...@@ -450,7 +450,6 @@ function image_resize_form($data) { ...@@ -450,7 +450,6 @@ function image_resize_form($data) {
'#default_value' => isset($data['width']) ? $data['width'] : '', '#default_value' => isset($data['width']) ? $data['width'] : '',
'#field_suffix' => ' ' . t('pixels'), '#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE, '#required' => TRUE,
'#size' => 10,
'#min' => 1, '#min' => 1,
); );
$form['height'] = array( $form['height'] = array(
...@@ -459,7 +458,6 @@ function image_resize_form($data) { ...@@ -459,7 +458,6 @@ function image_resize_form($data) {
'#default_value' => isset($data['height']) ? $data['height'] : '', '#default_value' => isset($data['height']) ? $data['height'] : '',
'#field_suffix' => ' ' . t('pixels'), '#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE, '#required' => TRUE,
'#size' => 10,
'#min' => 1, '#min' => 1,
); );
return $form; return $form;
...@@ -547,8 +545,6 @@ function image_rotate_form($data) { ...@@ -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.'), '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),
'#field_suffix' => '&deg;', '#field_suffix' => '&deg;',
'#required' => TRUE, '#required' => TRUE,
'#size' => 6,
'#maxlength' => 4,
); );
$form['bgcolor'] = array( $form['bgcolor'] = array(
'#type' => 'textfield', '#type' => 'textfield',
......
...@@ -91,8 +91,6 @@ function image_field_instance_settings_form($field, $instance) { ...@@ -91,8 +91,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Maximum width'), '#title' => t('Maximum width'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#default_value' => $max_resolution[0], '#default_value' => $max_resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1, '#min' => 1,
'#field_suffix' => ' x ', '#field_suffix' => ' x ',
); );
...@@ -101,8 +99,6 @@ function image_field_instance_settings_form($field, $instance) { ...@@ -101,8 +99,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Maximum height'), '#title' => t('Maximum height'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#default_value' => $max_resolution[1], '#default_value' => $max_resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1, '#min' => 1,
'#field_suffix' => ' ' . t('pixels'), '#field_suffix' => ' ' . t('pixels'),
); );
...@@ -122,8 +118,6 @@ function image_field_instance_settings_form($field, $instance) { ...@@ -122,8 +118,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Minimum width'), '#title' => t('Minimum width'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#default_value' => $min_resolution[0], '#default_value' => $min_resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1, '#min' => 1,
'#field_suffix' => ' x ', '#field_suffix' => ' x ',
); );
...@@ -132,8 +126,6 @@ function image_field_instance_settings_form($field, $instance) { ...@@ -132,8 +126,6 @@ function image_field_instance_settings_form($field, $instance) {
'#title' => t('Minimum height'), '#title' => t('Minimum height'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#default_value' => $min_resolution[1], '#default_value' => $min_resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1, '#min' => 1,
'#field_suffix' => ' ' . t('pixels'), '#field_suffix' => ' ' . t('pixels'),
); );
......
...@@ -389,8 +389,6 @@ function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight ...@@ -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' => $value !== '' ? t('Vote count for choice @label', array('@label' => $value)) : t('Vote count for new choice'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#default_value' => $votes, '#default_value' => $votes,
'#size' => 5,
'#maxlength' => 7,
'#min' => 0, '#min' => 0,
'#parents' => array('choice', $key, 'chvotes'), '#parents' => array('choice', $key, 'chvotes'),
'#access' => user_access('administer nodes'), '#access' => user_access('administer nodes'),
......
...@@ -93,9 +93,8 @@ function search_admin_settings($form) { ...@@ -93,9 +93,8 @@ function search_admin_settings($form) {
'#type' => 'number', '#type' => 'number',
'#title' => t('Minimum word length to index'), '#title' => t('Minimum word length to index'),
'#default_value' => variable_get('minimum_word_size', 3), '#default_value' => variable_get('minimum_word_size', 3),
'#size' => 5,
'#maxlength' => 3,
'#min' => 1, '#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).') '#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( $form['indexing_settings']['overlap_cjk'] = array(
......
...@@ -23,8 +23,6 @@ function image_gd_settings() { ...@@ -23,8 +23,6 @@ function image_gd_settings() {
'#type' => 'number', '#type' => 'number',
'#title' => t('JPEG quality'), '#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.'), '#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, '#min' => 0,
'#max' => 100, '#max' => 100,
'#default_value' => variable_get('image_jpeg_quality', 75), '#default_value' => variable_get('image_jpeg_quality', 75),
......
...@@ -405,9 +405,7 @@ function system_element_info() { ...@@ -405,9 +405,7 @@ function system_element_info() {
); );
$types['number'] = array( $types['number'] = array(
'#input' => TRUE, '#input' => TRUE,
'#size' => 30,
'#step' => 1, '#step' => 1,
'#maxlength' => 128,
'#process' => array('ajax_process_form'), '#process' => array('ajax_process_form'),
'#element_validate' => array('form_validate_number'), '#element_validate' => array('form_validate_number'),
'#theme' => 'number', '#theme' => 'number',
...@@ -415,11 +413,9 @@ function system_element_info() { ...@@ -415,11 +413,9 @@ function system_element_info() {
); );
$types['range'] = array( $types['range'] = array(
'#input' => TRUE, '#input' => TRUE,
'#size' => 30,
'#step' => 1, '#step' => 1,
'#min' => 0, '#min' => 0,
'#max' => 100, '#max' => 100,
'#maxlength' => 128,
'#process' => array('ajax_process_form'), '#process' => array('ajax_process_form'),
'#element_validate' => array('form_validate_number'), '#element_validate' => array('form_validate_number'),
'#theme' => 'range', '#theme' => 'range',
......
...@@ -365,6 +365,20 @@ class FormsTestCase extends DrupalWebTestCase { ...@@ -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. * Test handling of disabled elements.
* *
......
...@@ -145,6 +145,18 @@ function form_test_menu() { ...@@ -145,6 +145,18 @@ function form_test_menu() {
'page arguments' => array('form_test_number', 'range'), 'page arguments' => array('form_test_number', 'range'),
'access callback' => TRUE, '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( $items['form-test/checkboxes-radios'] = array(
'title' => t('Checkboxes, Radios'), 'title' => t('Checkboxes, Radios'),
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
...@@ -1276,6 +1288,80 @@ function form_test_number($form, &$form_state, $element = 'number') { ...@@ -1276,6 +1288,80 @@ function form_test_number($form, &$form_state, $element = 'number') {
return $form; 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. * Builds a form to test the placeholder attribute.
*/ */
......
...@@ -404,8 +404,6 @@ function user_admin_settings() { ...@@ -404,8 +404,6 @@ function user_admin_settings() {
'#type' => 'number', '#type' => 'number',
'#title' => t('Picture upload file size'), '#title' => t('Picture upload file size'),
'#default_value' => variable_get('user_picture_file_size', '30'), '#default_value' => variable_get('user_picture_file_size', '30'),
'#size' => 10,
'#maxlength' => 10,
'#min' => 0, '#min' => 0,
'#field_suffix' => ' ' . t('KB'), '#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.'), '#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.'),
......
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