I cannot create Number component that allows Decimal input that works in some browsers.
I've created a Number component, so I can enter data like "5.6".
Then Webform 7.x-3.18 generates HTML that looks like

Most browsers (IE, Firefox) ignore the type attribute if they don't handle it and treat it as a text field.
The latest versions of Chrome and Opera can handle type=number, but assume the field is an integer unless the Step attribute is also specified as "any".
will take any decimal input on most browsers.
Something like will work, but produces unexpected results for Chrome and Opera.

Webform will not generate step="any" for a Number component although you can specify the Step, and I'm not sure that those two browsers presently do the right thing.

I'm wondering if Webform should allow you to more explicitly request a decimal field and then add the 'any' attribute.
A workaround for me of course would be to rely upon a Textfield or to only allow integer input.

Here's the HTML5 spec.
http://www.w3.org/TR/2012/WD-html5-20120329/common-input-element-attribu...

I've attached sample HTML with notes about my browser observations.

CommentFileSizeAuthor
#3 webform_number_step_fixes.patch3.32 KBquicksketch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

druderman’s picture

Here's the sample HTML file.

<form>
Text: <input type="text" /><br /><br />
Integer: oddly allows any text input but not a decimal number 
<input type="number" min="0" /><br /><br />
Decimal: works in Chrome and Opera (needs attribute step="any" but can't do this in Webform) and works in Firefox and IE because they don't care. 
<input type="number" min="0" step="any" /><br /><br />
Decimal: fails in Chrome and in Opera (no attribute step="any"), and works in Firefox and IE because they don't care. 
<input type="number" min="0" /><br /><br />
<input type="submit" />
</form>
quicksketch’s picture

Category: feature » bug

Thanks @druderman, a great summary. Improvements to correct the behavior will certainly be welcomed; sounds like we need to figure out exactly what solution actually works across browsers.

quicksketch’s picture

Status: Active » Fixed
FileSize
3.32 KB

Re-reading your report and testing this out myself I understand what you're saying. Fortunately it looks like the two browsers that do implement "step" (Opera and Chrome) implement it in the same way which matches the spec. The bottom line is that we just need to set step="any" if a step is not defined and the number is not an integer.

This patch fixes the step problem and tidies up the number handling in a few additional ways to make it more compatible with Form Builder. Committed to both 3.x branches and the 7.x-4.x branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

update