Skip to content

The characters e., can be entered into number widgets with a valueType of int #1450

@papandreou

Description

@papandreou

- 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.

  1. Add a number field to a collection:
      -
        label: MyNumberField
        name: myNumberField
        widget: number
        valueType: int
  1. Create a new item in the collection
  2. Enter the text 123e in the field
  3. Press 1

Observe that the e disappears and the 1 doesn't get added(?)

  1. Press 1 again

Observe that the 1 does get added this time.

  1. Press e twice, then 1

Observe that ee is left alone and the content is now 123ee1

  1. Click Publish

Observe that the save is rejected with a MYNUMBERFIELD IS REQUIRED. message

  1. Change the value to 123..1
  2. Click Publish

Observe that the field gets persisted as:

myNumberField: .nan

- What is the expected behavior?

  • That ,, ., and e are suppressed when valueType is int. Alternatively that no keystrokes are suppressed and invalid numbers are dealt with when Publish is clicked.
  • That an accurate validation error is rendered when an invalid number has been entered
  • That garbage like .nan is never persisted :)
  • Maybe that 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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions