Fix handling of 'size' attribute on numeric inputs

Validators complain that SimpleForm's numeric elements have a `size`
attribute. According to the [spec][1], `input` elements with a `type`
of `number` must not specify a `size`. This change removes the `size`
option, and updates an existing unit test to guard against regressions.

Users may still provide a `size` option manually, though it may produce
invalid markup in certain situations.

[1]: http://www.whatwg.org/specs/web-apps/current-work/multipage/number-state.html#number-state
This commit is contained in:
Jason Petersen 2011-08-25 14:13:20 -07:00
parent 5d4021f6b5
commit 0332313300
2 changed files with 3 additions and 3 deletions

View File

@ -3,7 +3,7 @@ module SimpleForm
class NumericInput < Base
def input
input_html_options[:type] ||= "number" if SimpleForm.html5
input_html_options[:size] ||= SimpleForm.default_input_size
input_html_options[:size] ||= nil
input_html_options[:step] ||= integer? ? 1 : "any" if SimpleForm.html5
infer_attributes_from_validations! if SimpleForm.html5
@builder.text_field(attribute_name, input_html_options)

View File

@ -141,9 +141,9 @@ class InputTest < ActionView::TestCase
assert_select "input#user_password.password[type=password][name='user[password]']"
end
test 'input should use default text size for decimal attributes' do
test 'input should not use size attribute for decimal attributes' do
with_input_for @user, :credit_limit, :decimal
assert_select 'input.decimal[size=50]'
assert_no_select 'input.decimal[size]'
end
test 'input should get maxlength from column definition for string attributes' do