Skip to content

Commit

Permalink
Fix numeric inputs not submitting values if non digits are submitted …
Browse files Browse the repository at this point in the history
…in Firefox and Safari (#268)
  • Loading branch information
bameyrick authored Mar 4, 2019
1 parent 80a12a7 commit f5ad5c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/input/_template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
{% from "components/label/_macro.njk" import onsLabel %}

{% if params.type == "number" %}
{% set type = "number" %}
{# Type must be "text" or Firefox and Safari will set a blank value to the server if non numeric characters are entered -
they don't block non numeric characters: https://bugzilla.mozilla.org/show_bug.cgi?id=1398528 #}
{% set type = "text" %}
{% set pattern = "[0-9]*" %}
{% set inputmode = "numeric" %}
{% elif params.type %}
{% set type = params.type %}
{% else %}
Expand Down Expand Up @@ -49,9 +52,10 @@
{% if params.accept !== undefined %}accept="{{ params.accept }}"{% endif %}
{% if params.min !== undefined %}min="{{ params.min }}"{% endif %}
{% if params.max !== undefined %}max="{{ params.max }}"{% endif %}
{% if pattern !== undefined %}pattern="{{ pattern }}"{% endif %}
{% if inputmode != undefined %}inputmode="{{ inputmode }}"{% endif %}
{% if params.autocomplete !== undefined %}autocomplete="{{ params.autocomplete }}"{% endif %}
{% for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}

/>
{% if params.prefix !== undefined or params.suffix !== undefined %}
<abbr class="input-type__type" aria-hidden="true" title="{{ params.prefix.title }}{{ params.suffix.title }}">{{ params.prefix.text or params.prefix.title }}{{ params.suffix.text or params.suffix.title }}</abbr>
Expand Down
3 changes: 1 addition & 2 deletions src/components/input/examples/number/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"id": "number",
"type": "number",
"attributes": {
"min": 0,
"required": true
"min": 0
},
"label": {
"text": "Enter a number"
Expand Down

0 comments on commit f5ad5c3

Please sign in to comment.