Friday, February 15, 2013

Chrome Doesn't Allow Decimals In input type='number'

The current 'main' version of Google Chrome (24.0.1312.57 at the time of this writing) does not allow numbers with decimal points in input text boxes of type 'number'. Mozilla Firefox (18.0.2) and a few other browsers do not have this problem.

This decimal-related behavior is apparently not a flaw in Google Chrome.

Issue 44116: input type=number won't accept decimals

This issue is marked 'WontFix' and the behavior seems to be standards compliant. Included in the issue is a fix: specify the step attribute of the input. In Chrome, the default value of 'step' is '1', meaning that it only accepts integer input. If 'step' is set to 'any', the field allows decimal input.

So, to summarize:

This is bad, but works in Firefox:

<input type='number'
       name='amount' />


This is better for Chrome:

<input type='number'
       step='any'
       name='amount' />

No comments:

Post a Comment