Skip to content
This repository
Browse code

Remove 'size' attribute from number_field form helper fixes #3454

f.number_field generates <input type="number", size="30"../> which is
invalid HTML5. See: http://dev.w3.org/html5/spec/Overview.html#number-state
  • Loading branch information...
commit 56207a3f0165650abb273594f1f54fbb92bbf177 1 parent 533a9f8
Waseem Ahmad waseem authored
2  actionpack/lib/action_view/helpers/form_helper.rb
@@ -1027,6 +1027,8 @@ def to_input_field_tag(field_type, options = {})
1027 1027
1028 1028 def to_number_field_tag(field_type, options = {})
1029 1029 options = options.stringify_keys
  1030 + options['size'] ||= nil
  1031 +
1030 1032 if range = options.delete("in") || options.delete("within")
1031 1033 options.update("min" => range.min, "max" => range.max)
1032 1034 end
4 actionpack/test/template/form_helper_test.rb
@@ -438,12 +438,12 @@ def test_email_field
438 438 end
439 439
440 440 def test_number_field
441   - expected = %{<input name="order[quantity]" size="30" max="9" id="order_quantity" type="number" min="1" />}
  441 + expected = %{<input name="order[quantity]" max="9" id="order_quantity" type="number" min="1" />}
442 442 assert_dom_equal(expected, number_field("order", "quantity", :in => 1...10))
443 443 end
444 444
445 445 def test_range_input
446   - expected = %{<input name="hifi[volume]" step="0.1" size="30" max="11" id="hifi_volume" type="range" min="0" />}
  446 + expected = %{<input name="hifi[volume]" step="0.1" max="11" id="hifi_volume" type="range" min="0" />}
447 447 assert_dom_equal(expected, range_field("hifi", "volume", :in => 0..11, :step => 0.1))
448 448 end
449 449

0 comments on commit 56207a3

Please sign in to comment.
Something went wrong with that request. Please try again.