This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 30035 - Input type currency
Summary: Input type currency
Status: RESOLVED MOVED
Alias: None
Product: HTML.next
Classification: Unclassified
Component: default (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-19 19:33 UTC by Jeff Worthington
Modified: 2017-05-29 16:50 UTC (History)
3 users (show)

See Also:


Attachments

Description Jeff Worthington 2016-12-19 19:33:11 UTC
Input type of number is good for small numbers, but for currency amounts over 999 the unformatted number being input is hard to read. Imagine having to type in 45,000,000 without the visual feedback of the commas.

We can accomplish this with JavaScript (on an "input" event listener, e.g.):
	   function localizeCurrency() {
			var oldValue = this.value;
			this.rawValue = oldValue ? parseInt(oldValue.replace(/,/g, '')) : 0;
			if (oldValue) {
				var newValue = parseInt(oldValue.replace(/,/g, '')).toLocaleString();
				var caretPos = this.selectionStart - (oldValue.length - newValue.length);
				this.value = newValue;
				this.setSelectionRange(caretPos,caretPos);
			}
		}

But it requires an input type of "text" (to allow the commas to appear), and it would be much better to have this in the HTML itself.
<input type="currency" locale="usd">

As I type...what should appear
1           $1.00
10          $10.00
1000        $1,000.00
450000      $450,000.00
Comment 1 LĂ©onie Watson 2017-05-29 16:50:03 UTC
Moved to the HTML repo: 
https://github.com/w3c/html/issues/939