OptionController value coercing number to string
See original GitHub issueInside OptionController by using the HTML DOM option object and specifically the inherited setAttribute method any value in a list of possible options that should be a number will subsequently be converted into a string by the native implementation of setAttribute method.
Happens when wanting to have multiple numbers as options when using add with args that are of type:
add(target: Object, propName:string, items:number[]): GUIController;
https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Type Coercion with DataWeave - MuleSoft Documentation
First, you coerce a number value into String type to the specified output format that uses the Java DecimalFormat pattern (##) and also...
Read more >What's the best way to convert a number to a string in ...
pfx the question asks how to convert numeric values to a string. Providing examples of non-numeric values (e.g. null , undefined ) that...
Read more >Conversion rules | BigQuery - Google Cloud
Note: String literals do not coerce to numeric types. ... If the parameter value cannot be coerced successfully to the target type, an...
Read more >VALUE - Google Docs Editors Help
Converts a string in any of the date, time or number formats that Google Sheets understands into a number. Sample Usage VALUE("123") VALUE("7/20/1969") ......
Read more >Type coercion - MDN Web Docs Glossary
Type coercion is the automatic or implicit conversion of values from one data type to another (such as strings to numbers).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The values of a select input will always be of type string. That’s the HTML spec, and so cannot remain a number.
You could subscribe to the onchange event and coerce them back using Number or parseInt.
I was also stumped for a little while on how to elegantly solve this issue. The following function worked for me:
I do think that it would be good to mention this constraint (and perhaps provide alternative solutions such as the above function) somewhere in the documentation.