8000 [26.8] Fix multiselect chip clear for labeled user profile options by blakefrain · Pull Request #55140 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[26.8] Fix multiselect chip clear for labeled user profile options - #55140

Open
blakefrain wants to merge 6 commits into
keycloak:release/26.8from
blakefrain:cursor/backport-multiselect-chip-clear-26-8-5668
Open

blakefrain wants to merge 6 commits into
keycloak:release/26.8from
blakefrain:cursor/backport-multiselect-chip-clear-26-8-5668

Conversation

@blakefrain
Copy link
Copy Markdown
Contributor

Backport of #55021 to release/26.8.

Fixes clearing and saving empty values for user profile attributes with inputType=multiselect when inputOptionLabels differ from option keys.

Root cause

Chip removal used display labels as selections while toggle/remove compared against option keys, so clicking X could add the label instead of removing the value.
After a successful clear, PUT sent an empty array and the server removed the attribute, but GET omits empty attributes. form.reset(toUserFormFields(user)) then rebuilt form state without that key, so react-hook-form kept the previous nested value and the chip reappeared until a hard reload.

Fix

Keep option keys as selections and render labels via chipGroupComponent, clearing multiselect to [].
Seed managed profile attributes with empty values in toUserFormFields from user profile metadata so reset explicitly clears omitted attributes.
Reuse shared isRootAttribute from @keycloak/keycloak-ui-shared (no local duplicate).

How to verify

Configure an optional multiselect attribute with an options validator, inputOptionsFromValidation, and labels that differ from keys (max=1).
Select a value, save, clear the chip with X, save again — the field should stay empty and save successfully.
Hard refresh should still show an empty selection.

Refs #55020

AI disclosure

This change was produced with assistance from a Cursor cloud agent.

When inputOptionLabels differed from option keys, chip selections used
display labels while toggle/remove compared against option keys, so
clicking X added the label instead of removing the value. Keep option
keys as selections, render labeled chips via chipGroupComponent, and
clear multiselect to an empty array.

Closes keycloak#55020

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Closes keycloak#55020

Keycloak omits empty attributes from GET user responses. After clearing a
multiselect chip and saving, form.reset rebuilt values without that key,
so react-hook-form kept the previous nested value and the chip returned.
Seed managed profile attributes with empty values when converting to form
fields so reset explicitly clears them.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Export isRootAttribute from @keycloak/keycloak-ui-shared and use it in
toUserFormFields instead of a local duplicate.

Closes keycloak#55020

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0