data-driven-forms / react-forms

React library for rendering forms.
https://data-driven-forms.org/
Apache License 2.0
295 stars 85 forks source link

When passing the initialValues { SELECT_OPTION : 0 } in schema then in select that value not showing as selected. #1433

Open anjalikalsariya opened 8 months ago

anjalikalsariya commented 8 months ago

Select field

{
      "name": "SELECT_OPTION",
      "label": "test",
      "options": [
        { "label": "none", "value": 0 },
        { "label": "2", "value": 2 },
      ],
      "component": "select"
    },
Note:  I'm using the ant-component-mapper.

Can you help me for it?

rvsia commented 8 months ago

This is because javascript resolves 0 as false so the select thinks there is no value. @Hyperkid123 we could probably fix it. As a workaround, @anjalikalsariya, use string and then convert it to a number. 😸

anjalikalsariya commented 8 months ago

Correct @rvsia. I got it. For now, let me add that convert solution. Later, If anything will be changing in the library to fix this issue that will be more helpful.

anjalikalsariya commented 8 months ago

One more thing is when the value is 0 and validation is required then also throws an error for an empty field. Validation does not work with the value 0 integer.