- Do you want to request a feature or report a bug?
bug
- What is the current behavior?
The number widget seems to suppress all characters that aren't digits, e, ., +, -, or ,. (I assume the reason why e and + are allowed is to support exponential notation?)
However, these characters are also allowed for number fields with a valueType of int. An attempt is made to sanitize them later, but it doesn't quite work and can lead to the field containing the string .nan.
- If the current behavior is a bug, please provide the steps to reproduce.
-
label: MyNumberField
name: myNumberField
widget: number
valueType: int
123e in the field1Observe that the e disappears and the 1 doesn't get added(?)
1 againObserve that the 1 does get added this time.
e twice, then 1Observe that ee is left alone and the content is now 123ee1
Observe that the save is rejected with a MYNUMBERFIELD IS REQUIRED. message
123..1Observe that the field gets persisted as:
myNumberField: .nan
- What is the expected behavior?
,, ., and e are suppressed when valueType is int. Alternatively that no keystrokes are suppressed and invalid numbers are dealt with when Publish is clicked..nan is never persisted :)e, + and , aren't allowed at all, even when valueType is float or not specified. It seems unlikely that anyone would want to use exponential notation in a CMS.- Please mention your versions where applicable.
Netlify CMS version: 1.9.2
Browser version: Chrome 67.0.3396.87/OSX
Node.JS version: 10.4.1
Operating System: Mac OSX 10.13.5 (High Sierra)
The number widget really isn't doing anything here - HTML number inputs accept those characters for scientific notation, and no effort has been made to validate within the CMS. A validation method should be added, perhaps using a library that handles number validation comprehensively rather than reinventing the wheel.
@erquhart, ah, you're right about <input type=number> causing most of the weirdness. That thing seems terrible :)
I believe this is addressed in #2067, will release soon.