Checkbox validation on register form

Working on a v26 of Keycloak, I want to add three new fields on a registration form, three checkbox to ask to the user the consent to privacy, terms and conditions and marketing usage.

I know that there is a dedicated flow to the terms and condition but the fact that it turns out to be on a different page than the registration form is not good for my specific case.

So i decide to add three attribute field on My Realm > Realm settings > User profile > Create attribute section, using the multiselect-checkbox inputType with only one option. I have see that this seems to be the most common way for inserting a single checkbox into the form, please help me understand if this is correct.

But, when I add the first attribute, I share the generated json:

{
      "name": "marketing",
      "displayName": "${profile.attributes.marketing}",
      "validations": {
        "options": {
          "options": [
            "1"
          ]
        }
      },
      "annotations": {
        "inputHelperTextAfter": "Lorem Ipsum",
        "inputType": "multiselect-checkboxes"
      },
      "permissions": {
        "view": [
          "admin",
          "user"
        ],
        "edit": [
          "admin",
          "user"
        ]
      },
      "multivalued": false
    }

The field is not validating right.

  • If I enable the required option, the form can be submitted even if the user has not check the field.
  • if I check the field (both when is mandatory and when not) a validator error is shown that is not very clear to me (image below)

I’m probably forgetting something in the attribute validation section, can you help me figure out what?

I need to trace this selection in the database, what are the suggested best practice for handling these types of fields?

Thanks all

So I have an update on the topic.

I resolved the validation of the field error, simply with enabling the Multivalued option without other validations, as showed below:

Now the form can be submitted when the user add check mark on that field.

The missing validation, when the multiselect-checkboxes field is requires, remains a mystery, even if I change the input type into select-radiobuttons and add two options value (accept and decline) the validation doesn’t work properly, the user can submit the registration form even by not filling the field.

On this last point would you know how to guide me toward a solution?