-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use index for value in SelectWidget #1562
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a great improvement!
return i; | ||
} | ||
} | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return an empty string by default?
Could we just return undefined
instead -- so that it would also be possible to select ""
? (an additional improvement from the old code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like a good idea, will look into it
}}> | ||
{!multiple && schema.default === undefined && ( | ||
<option value="">{placeholder}</option> | ||
)} | ||
{enumOptions.map(({ value, label }, i) => { | ||
const disabled = enumDisabled && enumDisabled.indexOf(value) != -1; | ||
return ( | ||
<option key={i} value={value} disabled={disabled}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely a breaking change because it changes what's rendered in the DOM (the value
)... but it's fine to go into version 2, and worth it to allow for better selection of any kinds of enums.
Good to hear, what can I do help this get landed? Not really sure how to proceed. Lots of tests are failing, but as they are written now they would become kind of pointless as most tests I saw focus on checking the values in the DOM render which are just a bunch of integers with this change. |
It seems that many of the tests are failing because |
d3ccbd3
to
afe1971
Compare
afe1971
to
47aed5f
Compare
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the `playground` to add the new `Enumerated Object` example - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Updated `optionId()` to take an index rather than an option - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Also passed index to `optionId()` rather than option - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the `playground` to add the new `Enumerated Object` example - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Updated `optionId()` to take an index rather than an option - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Also passed index to `optionId()` rather than option - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the `playground` to add the new `Enumerated Object` example - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Updated `optionId()` to take an index rather than an option - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Also passed index to `optionId()` rather than option - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the `playground` to add the new `Enumerated Object` example - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Fixes rjsf-team#1494, reimplementing rjsf-team#1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Updated `optionId()` to take an index rather than an option - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Also passed index to `optionId()` rather than option - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the `playground` to add the new `Enumerated Object` example - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly
Implemented this fully for all widgets that use |
* Fix: switch enumOptions rendering widgets to use indexes Fixes #1494, reimplementing #1562 to make all widgets that render `enumOptions` switch from option value to option index - In `@rjsf/utils`, added/updated `enumOptionsXXXX` methods that enable using index instead of values - Added 100% unit tests for these new methods - Updated `optionId()` to take an index rather than an option - Also remove the now unnecessary `processSelectValue()` function and its unit test - In all themes, updated the `CheckboxesWidget`, `RadioWidget` and `SelectWidget` to use the `enumOptions[]` index rather than value for the html elements - Utilized the new `enumOptionsXXXX` methods to facilitate this transformation - Also passed index to `optionId()` rather than option - Updated the tests in `core` and snapshots in the other themes to represent this change from value to index - Updated the `playground` to add the new `Enumerated Object` example - Updated the documentation for the new methods and the breaking change this causes - Updated the `CHANGELOG.md` file accordingly * Apply suggestions from code review Co-authored-by: Nick Grosenbacher <[email protected]> --------- Co-authored-by: Nick Grosenbacher <[email protected]>
This PR changes the way options are selected in the SelectWidget by using the options array index instead of a serializing the selected value to the DOM (cast to string). This allows removal of a lot of hacky code to guess type of deserialized values, and also allows for selecting complete objects via a dropdown, addressing #1494.
I've added a playground example. I haven't looked at fixing the tests yet as would like feedback on the approach first.