react-components-form icon indicating copy to clipboard operation
react-components-form copied to clipboard

SelectField don't support null type

Open ad-boschung opened this issue 7 years ago • 3 comments

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 ?

ad-boschung avatar Feb 20 '19 14:02 ad-boschung

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

mprzodala avatar Feb 23 '19 18:02 mprzodala

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 avatar Mar 28 '19 11:03 ad-boschung

@mprzodala or @wysher Any news about this issue ?

ad-boschung avatar May 15 '19 15:05 ad-boschung