Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum validation fails for numbers #1098

Closed
2 tasks done
ksheedlo opened this issue Dec 6, 2018 · 4 comments
Closed
2 tasks done

Enum validation fails for numbers #1098

ksheedlo opened this issue Dec 6, 2018 · 4 comments

Comments

@ksheedlo
Copy link

ksheedlo commented Dec 6, 2018

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

react-jsonschema-form fails validation when the schema field has enum validation and a number is selected.

Steps to Reproduce

  1. Go to https://codesandbox.io/s/21j3m9m5qr
  2. Select 1 from the dropdown (also works with 2 or 3)
  3. Click submit

Expected behavior

The demo application should display the following content JSON in the pre tag:

{
  "count": 1
}

Actual behavior

Validation failed, and the following error message was produced.

screen shot 2018-12-05 at 4 24 15 pm

Version

1.0.6

@LucianBuzzo
Copy link
Collaborator

The issue here is that the default Select widget just uses event.target.value to retrieve the selected value on change, which by default is always a string. https://github.com/mozilla-services/react-jsonschema-form/blob/master/src/components/widgets/SelectWidget.js#L32

@LucianBuzzo
Copy link
Collaborator

LucianBuzzo commented Dec 6, 2018

You can work around this by setting the type keyword in your schema, so that react-jsonschema-form can correctly infer the type you are expecting, for example:

const SCHEMA = {
  type: "object",
  properties: {
    count: {
      enum: [1, 2, 3],
      type: "number"
    }
  }
};

@LucianBuzzo
Copy link
Collaborator

I've opened a PR to infer the type from the enum if type is not present in the schema #1100

edi9999 pushed a commit that referenced this issue Dec 13, 2018
Connects to #1098

Change-type: minor
Signed-off-by: Lucian <lucian.buzzo@gmail.com>
pieplu pushed a commit to pieplu/react-jsonschema-form that referenced this issue Dec 14, 2018
…team#1100)

Connects to rjsf-team#1098

Change-type: minor
Signed-off-by: Lucian <lucian.buzzo@gmail.com>
@glasserc
Copy link
Contributor

As #1100 was merged and released in v1.0.7, I'm closing this. Please let me know if the problem persists.

epicfaace pushed a commit that referenced this issue Mar 5, 2019
* Infer type from enum if a type is not provided to SelectWidget (#1100)

Connects to #1098

Change-type: minor
Signed-off-by: Lucian <lucian.buzzo@gmail.com>

* No more useless div on schema field not additional

* Fix tests (remove useles html)
- Revert some test added by
https://github.com/mozilla-services/react-jsonschema-form/pull/1123/files
- use new css class for form-additional insted layout css class
for test selection

* Don't use WrapIfAdditonal Component to hav a clerer diff, but adding code duplicate

* Use a WrapIfAdditional Component to have a cleanner code / diff

* Fix tests

* Ignore vscode Ide folder

* Remove useless parentProps

* Fix old test selector for form additional
CodeGains pushed a commit to CodeGains/react-jsonschema-form that referenced this issue Mar 5, 2019
…team#1158)

* Infer type from enum if a type is not provided to SelectWidget (rjsf-team#1100)

Connects to rjsf-team#1098

Change-type: minor
Signed-off-by: Lucian <lucian.buzzo@gmail.com>

* No more useless div on schema field not additional

* Fix tests (remove useles html)
- Revert some test added by
https://github.com/mozilla-services/react-jsonschema-form/pull/1123/files
- use new css class for form-additional insted layout css class
for test selection

* Don't use WrapIfAdditonal Component to hav a clerer diff, but adding code duplicate

* Use a WrapIfAdditional Component to have a cleanner code / diff

* Fix tests

* Ignore vscode Ide folder

* Remove useless parentProps

* Fix old test selector for form additional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants