Permalink
Browse files

Override rails default size for numeric inputs

  • Loading branch information...
haines committed Dec 29, 2011
1 parent 6ae39e9 commit 7f612bbebeffe48ca3cb086d478dbf5a8055bb8a
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/formtastic/inputs/base/numeric.rb
@@ -4,6 +4,10 @@ module Base
module Numeric
def input_html_options
defaults = super
+
+ # override rails default size - not valid on numeric inputs
+ #@todo document/spec
+ defaults[:size] = nil
if in_option
defaults[:min] = in_option.to_a.min

6 comments on commit 7f612bb

@themactep

This comment has been minimized.

Show comment Hide comment
@themactep

themactep Jul 14, 2012

Contributor

This makes it impossible to add a size attribute to number input controls. I believe 'size' is still a valid attribute, see DOM interface http://www.w3.org/TR/html-markup/input.number.html

Contributor

themactep replied Jul 14, 2012

This makes it impossible to add a size attribute to number input controls. I believe 'size' is still a valid attribute, see DOM interface http://www.w3.org/TR/html-markup/input.number.html

@haines

This comment has been minimized.

Show comment Hide comment
@haines

haines Jul 14, 2012

Contributor

According to MDN:

Starting in HTML5, this attribute applies only when the type attribute is set to text, search, tel, url, email, or password; otherwise it is ignored.

So while it might strictly be valid, it's not terribly useful. My bad for not getting that right in the comment, will fix when I'm back at my computer!

Contributor

haines replied Jul 14, 2012

According to MDN:

Starting in HTML5, this attribute applies only when the type attribute is set to text, search, tel, url, email, or password; otherwise it is ignored.

So while it might strictly be valid, it's not terribly useful. My bad for not getting that right in the comment, will fix when I'm back at my computer!

@haines

This comment has been minimized.

Show comment Hide comment
@haines

haines Jul 15, 2012

Contributor

Have changed the wording from "not valid" to "does not apply" - see 4543f44

Contributor

haines replied Jul 15, 2012

Have changed the wording from "not valid" to "does not apply" - see 4543f44

@themactep

This comment has been minimized.

Show comment Hide comment
@themactep

themactep Jul 15, 2012

Contributor

Can you remove this portion of code altogether instead? I don't see why you need to force-strip a valid attribute. The size attribute is intended to set the number of characters that can be seen at once, and it does apply to number inputs.

UPD: Seems Chrome does not respect the size attribute. It defaults to 20 and does not change size of the field whatever value I feed it. Firefox changes the field size according to the value. Weird.

Contributor

themactep replied Jul 15, 2012

Can you remove this portion of code altogether instead? I don't see why you need to force-strip a valid attribute. The size attribute is intended to set the number of characters that can be seen at once, and it does apply to number inputs.

UPD: Seems Chrome does not respect the size attribute. It defaults to 20 and does not change size of the field whatever value I feed it. Firefox changes the field size according to the value. Weird.

@justinfrench

This comment has been minimized.

Show comment Hide comment
@justinfrench

justinfrench Jul 15, 2012

Owner

@themactep If we can't remove it, or we're concerned that it might introduce an edge case regression, I think we can still accommodate you by checking if there's a key set:

defaults[:size] = nil unless defaults.key?(:size)

Would happily accept a patch with test coverage, otherwise please create an issue to track rather than this comment thread. I won't have time in the next few days.

Owner

justinfrench replied Jul 15, 2012

@themactep If we can't remove it, or we're concerned that it might introduce an edge case regression, I think we can still accommodate you by checking if there's a key set:

defaults[:size] = nil unless defaults.key?(:size)

Would happily accept a patch with test coverage, otherwise please create an issue to track rather than this comment thread. I won't have time in the next few days.

@haines

This comment has been minimized.

Show comment Hide comment
@haines

haines Jul 16, 2012

Contributor

The following content attributes must not be specified and do not apply to the element: accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, maxlength, multiple, pattern, size, src, and width.

http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#number-state-(type=number)

Contributor

haines replied Jul 16, 2012

The following content attributes must not be specified and do not apply to the element: accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, maxlength, multiple, pattern, size, src, and width.

http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#number-state-(type=number)

Please sign in to comment.