Skip to content
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

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

Closed
justlevine opened this issue Jul 30, 2023 · 8 comments

Comments

@justlevine
Copy link

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 2de3fbe

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
Copy link
Author

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 😕

@mrksdiehl
Copy link

Same issue here.

@MattOndo
Copy link

MattOndo commented Nov 7, 2023

Bumping, same issue here

@amirnaderi
Copy link

Any updates about this issue!?

@laurensdacosta
Copy link

Also need an update on this issue!

@nestle49
Copy link

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

@atanas-vasilev-dev
Copy link
Collaborator

Fixed and coming in next release, see here:
#1205

@atanas-vasilev-dev
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants