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

SelectField don't support null type #75

Open
ad-boschung opened this issue Feb 20, 2019 · 3 comments
Open

SelectField don't support null type #75

ad-boschung opened this issue Feb 20, 2019 · 3 comments

Comments

@ad-boschung
Copy link

I've a SelectField with a list of options in my schema.
One item can be null and if it's null it's crashing.

It seams that the field don't support a null value.
It's a bit painful because if a property is not required it's logical that this property is null.

I've create an example in CodeSandbox for you : https://codesandbox.io/s/pkq11l9zk7.

Do you have an idea how to manage this use case ?

@mprzodala
Copy link
Collaborator

Look on this example https://codesandbox.io/s/2wyj92lx5j I think this should resolve this use case.

@ad-boschung
Copy link
Author

I've looked your example. But it doesn't work as expected, because of the following reasons :

  • Your example don't do really what i need.
  • In the getDerivedStateFromProps method you don't take the correct next props correctly.
  • I don't want to have a form on the HTML for every items (maybe 4000 items). Hidden or not, the code is present on the page. Not so good for performance...

I've create a new sandbox to demonstrate the bug correctly :
Sandbox link : https://codesandbox.io/s/xrjxk9oozz

That's what I need to do :

  • I have an object "Activity" which contains an other object "Category"
  • The category object can be null, or contains and id or a name.
  • In the form I only want to display one field for the category, not all object fields.
  • The form should present the category in a SelectField.
  • The SelectField options definition : id as value, name as label
  • When submit, the category id should be null (if nothing selected) or a number.

BUG : With the sandbox implementation I made, it's crashing when the category is null !!

JSON Activity Object

activity : { 
    ...,
    category : {
          id: xxx,
          name: "xxx"
    }
}

Behavior needed :

category value Display Value on submit
{category:null} Screenshot 2019-03-28 at 11 44 40 {category: null}
{category: id: 1, name: "Category 1"} Screenshot 2019-03-28 at 11 44 48 {category: id: 1}

@ad-boschung
Copy link
Author

ad-boschung commented May 15, 2019

@mprzodala or @wysher Any news about this issue ?

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

2 participants