googlearchive / core-input

A single-line text field with some extra powers
7 stars 20 forks source link

The value entered into <core-input type="number"> is string #26

Closed GabiAxel closed 9 years ago

GabiAxel commented 10 years ago

It would be nice if the component parsed and converted the value and inputValue properties to numbers for type="number".

ssorallen commented 9 years ago

The value attribute of an HTMLInputElement is always a string: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

Since core-input extends <input>, Polymer can't intercept calls to value (as said by @azakus) to return something other than a string. And since this extends a native element, it seems undesirable to change the native interface even if it were possible.

ssorallen commented 9 years ago

Aha, you can simply use the native valueAsNumber attribute of HTMLInputElement. If the type is set to number, that attribute will return a number:

> var el = document.createElement("input");
> el.type = "number";
> el.value = "1234";
> el.value
"1234"
> el.valueAsNumber
1234