carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Multiselect error when removing only option: `Uncaught TypeError: Cannot read properties of null (reading 'map')`

Open justlevine opened this issue 1 year ago • 6 comments

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')

image

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

  1. Select an item or several in the Multiselect field.
  2. Try to remove all selected items from the Multiselect field.
  3. When attempting to remove the last item, note it does note get removed. See console log.

Comments

Please add any other comments here

justlevine avatar Jul 30 '23 18:07 justlevine

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 😕

justlevine avatar Jul 31 '23 05:07 justlevine

Same issue here.

mrksdiehl avatar Aug 11 '23 13:08 mrksdiehl

Bumping, same issue here

MattOndo avatar Nov 07 '23 01:11 MattOndo

Any updates about this issue!?

amirnaderi avatar Nov 08 '23 17:11 amirnaderi

Also need an update on this issue!

laurensdacosta avatar Dec 20 '23 21:12 laurensdacosta

@vvasilev- @atanas-dev @jorostoyanov anybody else?

nestle49 avatar May 26 '24 11:05 nestle49

Fixed and coming in next release, see here: https://github.com/htmlburger/carbon-fields/issues/1205

atanas-vasilev-dev avatar Jul 24 '24 06:07 atanas-vasilev-dev

The fix for this issue is now released in https://github.com/htmlburger/carbon-fields/releases/tag/v3.6.5

atanas-vasilev-dev avatar Jul 31 '24 08:07 atanas-vasilev-dev