Skip to content

Carbon Multi Select Not Resetting Correctly With Form Reset #1412 #1413

Description

@GilbertCherrie

Possible bug found with the carbon multi select component and the form reset functionality. I am running into an issue where resetting a form correctly returns all fields to initial values except the mutli select field. It seems to be receiving the correct values after clicking reset (the initial selected values) but the component seems to not react to this change visually as it still holds whatever check boxes were checked before hitting the reset button.

Activity

  1. Hyperkid123 commented on Sep 14, 2023

    @Hyperkid123
    Member

    @GilbertCherrie can you provide the form schema, please?

  2. GilbertCherrie commented on Sep 14, 2023

    @GilbertCherrie
    ContributorAuthor

    Form schema:

        {
          component: componentTypes.TEXT_FIELD,
          label: __('Full Name'),
          maxLength: 50,
          id: 'name',
          name: 'name',
          isDisabled: disabled,
          isRequired: true,
          validate: [{
            type: validatorTypes.REQUIRED,
            message: __('Required'),
          }],
        },
        {
          component: componentTypes.TEXT_FIELD,
          label: __('Username'),
          maxLength: 255,
          id: 'userid',
          name: 'userid',
          isDisabled: disabled,
          isRequired: true,
          validate: [{
            type: validatorTypes.REQUIRED,
            message: __('Required'),
          }],
        },
        ...(id ? [
          ...(editMode ? [
            {
              component: 'edit-password-field',
              label: __('Password'),
              id: 'password',
              name: 'password',
              maxLength: 50,
              editMode,
              disabled: !editMode,
              setEditMode: () => {
                setState((state) => ({
                  ...state,
                  editMode: !editMode,
                }));
              },
              placeholder: '●●●●●●●●',
              buttonLabel: editMode ? __('Cancel') : __('Change'),
            },
            {
              component: componentTypes.TEXT_FIELD,
              label: __('Confirm Password'),
              maxLength: 50,
              type: 'password',
              id: 'confirmPassword',
              name: 'confirmPassword',
              initialValue: '',
              isRequired: true,
            },
          ] : [
            {
              component: 'edit-password-field',
              label: __('Password'),
              maxLength: 50,
              id: 'passwordPlaceholder',
              name: 'passwordPlaceholder',
              editMode,
              disabled: true,
              setEditMode: () => {
                setState((state) => ({
                  ...state,
                  editMode: !editMode,
                }));
              },
              placeholder: '●●●●●●●●',
              buttonLabel: editMode ? __('Cancel') : __('Change'),
            },
          ]),
        ] : [
          {
            component: componentTypes.TEXT_FIELD,
            label: __('Password'),
            maxLength: 50,
            type: 'password',
            id: 'password',
            name: 'password',
            isRequired: true,
            validate: [{
              type: validatorTypes.REQUIRED,
              message: __('Required'),
            }],
          },
          {
            component: componentTypes.TEXT_FIELD,
            label: __('Confirm Password'),
            maxLength: 50,
            type: 'password',
            id: 'confirmPassword',
            name: 'confirmPassword',
            initialValue: '',
            isRequired: true,
            validate: [{
              type: validatorTypes.REQUIRED,
              message: __('Required'),
            }],
          },
        ]),
        {
          component: componentTypes.TEXT_FIELD,
          label: __('E-mail Address'),
          maxLength: 255,
          id: 'email',
          name: 'email',
          validate: [{
            type: validatorTypes.PATTERN,
            pattern: '[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$',
            message: __('Email must be a valid email address'),
          }],
        },
        {
          component: componentTypes.SELECT,
          label: __('Available Groups'),
          id: 'groups',
          name: 'groups',
          isDisabled: disabled,
          isMulti: true,
          isRequired: true,
          placeholder: __('<Choose one or more Groups>'),
          options: availableGroups,
          validate: [{
            type: validatorTypes.REQUIRED,
            message: __('Required'),
          }],
          onChange: (values) => {
            const groups = [];
            values.forEach((group) => {
              if (group.label) {
                groups.push(group.label);
              } else {
                availableGroups.forEach((availableGroup) => {
                  if (availableGroup.value === group) {
                    groups.push(availableGroup.label);
                  }
                });
              }
            });
            setState((state) => ({
              ...state,
              selectedGroups: groups,
            }));
          },
        },
    
  3. GilbertCherrie commented on Sep 14, 2023

    @GilbertCherrie
    ContributorAuthor

    Some of the components in the schema have some custom functionality but I noticed this same issue with other simpler forms that use this component as well so I don't think the custom functionality should be an issue. I also noticed this issue before any of the onChange code was added to the component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions