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