Checkbox custom form field works weird
-
After upgrading from 1.19 to 1.22.1 when I try to create form field as Checkbox control of type Boolean and assign its value to user.data.subscribe, FusionAuth forces me to provide a list of options. I believe it should work just as single boolean value: true or false.
-
We need to update the documentation about this. We had some internal discussions about what to do with this case, which I agree, is a bit weird. Eventually we decided that what you see was the best option.
The only allowed values are true and false. In theory you could have a checkbox of boolean with only one value of
true
(or one value offalse
), so by allowing them to enter the values, they can make this choice. -
Thank you for the clarification! It still looks a bit odd. For example if you provide both options, true and false, for the single Checkbox field, you will actually see two checkboxes on the form. And even can check them both.
And the value in you custom data becomes not boolean, but array of booleans.
Still it does what I need and even more. I have problems with Complete Registration form: it just crashes when the Self-consent field is the only field required to complete registration (will open the Issue on GitHub).
But now if you set the only one option (true) for the Checkbox field and make it required, it can nicely serve as a Consent field. -
After some further thought, I believe this is working as designed, though I agree this is weird.
When you create a checkbox and provide options, we display each option as a choice.
If you didn't want it to display
true
orfalse
you could create a messages entry for that field. (In the theme admin section; more here: https://fusionauth.io/blog/2020/09/01/theme-registration-form/ ).But I agree, I think in general you don't want to use checkboxes with multiple booleans, a select box is a better choice.