Uploaded image for project: 'Red Hat build of Keycloak'
  1. Red Hat build of Keycloak
  2. RHBK-2656

Multiselect Checkboxes in user profile don't allow to unset value [GHI#35352]

XMLWordPrintable

    • False
    • Hide

      None

      Show
      None
    • False

      Before reporting an issue

      [X] I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

      Area

      user-profile

      Describe the bug

      When input type multiselect-checkboxes is used to render one or more checkboxes in the profile, the user can check the boxes and the values get saved.
      However when the user updates the profile and unchecks all boxes, this is not saved.

      This makes the input type also unusable for single checkbox, as the user can't unset the value once it is stored.

      Version

      26.0.6

      Regression

      [ ] The issue is a regression

      Expected behavior

      User can unselect all checboxes and this gets saved.

      Actual behavior

      When no box is checked, the browser doesn't submit a value for the attribute. Stored values at server side remain unchanged.

      How to Reproduce?

      Define an attribute with input type "multiselect-checkboxes" and add a Validator with options:

      ```

      { {code}

      "name": "Checkboxes",
      "displayName": "",
      "validations": {
      "options":

      { "options": [ "A", "B", "C" ] }

      },
      "annotations":

      { "inputType": "multiselect-checkboxes" }

      ,
      "permissions":

      { "view": [ "user" ], "edit": [ "admin", "user" ] }

      ,
      "multivalued": true
      }

      
      

      ```

      User checks all options. They are stored as expected:
      <img src="https://github.com/user-attachments/assets/6c801ff5-13e5-4d01-80b3-7129702b8b79" width=50%>

      On next user profile update, when all boxes are unchecked, the attribute isn't sent to the server:
      <img src="https://github.com/user-attachments/assets/0af7c4f3-5e34-4086-9f67-bbea38f8459e" width=50%>
      Form data sent:
      ```firstName=test&lastName=test```
      The previously selected values A, B, C remain stored.

      It works as expected if one or more boxes are still checked:
      <img src="https://github.com/user-attachments/assets/46180e5d-0ed2-401e-a15f-43e93ffa84ef" width=50%>
      Form data sent:
      ``firstName=test&lastName=test&Checkboxes=A&Checkboxes=C``

      Anything else?

      The bug was found in Keycloak 24 and is still present in Keycloak 26.

      Proposed solution: Add a hidden input element with same name and value "null". On server side remove the "null" String value from the received list of values when input type is multiselect-checkboxes.

              Unassigned Unassigned
              pvlha Pavel Vlha
              Keycloak UI
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: