carbon-fields
carbon-fields copied to clipboard
Multiselect error when removing only option: `Uncaught TypeError: Cannot read properties of null (reading 'map')`
Version
- Carbon Fields: 3.6.0
- WordPress: 5.9.7
- PHP: 7.4
Expected Behavior
Please enter the expected behavior here
I should be able to remove the last selected option from a multiselect form.
Actual Behavior
Please enter the actual, unexpected behavior here
Instead of the option getting removed, nothing happens, and I get a console error: Uncaught TypeError: Cannot read properties of null (reading 'map')
This seems to be caused by the use of selected.map()
instead of selected?.map()
in handleChange
means the value is not an array. (not sure if this is a change in behavior in react-select@v3 https://github.com/htmlburger/carbon-fields/commit/2de3fbe44d5e063dece9bd40900e54dc7ff4addd
Container definition
// Please add your entire container defintion here so issues
// are easy to reproduce
Container::make( 'theme_options', 'Harness Settings' )
->set_page_parent( 'options-general.php' )
->add_fields(
Field::make( 'multiselect', self::MODULE_HIDE_LIST, __( 'Modules to disable on the frontend.', 'harness' ) )->set_options(
[
'certifications' => 'Certifications',
'corrective-actions' => 'Corrective Actions',
'documents' => 'Documents',
'equipment' => 'Equipment',
'notifications' => 'Notifications',
]
)
->set_help_text( 'Selected modules / features will be hidden / disabled on the frontend.' )
)
Steps to Reproduce the Problem
- Select an item or several in the Multiselect field.
- Try to remove all selected items from the Multiselect field.
- When attempting to remove the last item, note it does note get removed. See console log.
Comments
Please add any other comments here
values.map
in Multiselect's filterValues
also needs to be made nullable.
I tried making a PR, but I cannot get the build script to run correctly using either NPM or Yarn 😕
Same issue here.
Bumping, same issue here
Any updates about this issue!?
Also need an update on this issue!
@vvasilev- @atanas-dev @jorostoyanov anybody else?
Fixed and coming in next release, see here: https://github.com/htmlburger/carbon-fields/issues/1205
The fix for this issue is now released in https://github.com/htmlburger/carbon-fields/releases/tag/v3.6.5