Required text field if checkbox is checked

I’ve a binder that has a checkbox. If the checkbox is checked a TextField is shown.
This TextField should be required if the checkbox is checked. The only way I’ve seen to do this is using setAsRequiredEnabled on an existing binding. As per source code this sadly instantly validates the form This leads to a pretty bad UI/UX for the user who checks the checkbox and instantly sees a big red box. Is there any way around it?

Personally, I remove the old binding of the text field and create a new one with the correct required state, this shouldn’t call any validator

I tried that too but I had problems with binder.readBean(null) then. It ended up in a ConcurrentModificationException. I think that’s the case because the readBean tried to clear the fields and the value change listener for the checkbox is called which tried to remove the binding. I may be wrong tho.

I don’t use readBean, so I can’t really comment on that behavior. :sweat_smile:

How else do you clear the form?

I’m using setBean with an empty bean

hmm validation on the checkboxgroup is still called even if I use setBean

Oh Checkboxgroup… that’s an important info… I remember that there it works (not sure if intended) like this… that I can sadly confirm :grimacing: I haven’t digged deeper if bug or something else… it’s probably worth to create a issue in the flow-components repo

yeah sorry I wanted to make the case more simple and wrote the example with checkbox only

but thanks, will open up an issue

Checkboxgroup + RadioButtonGroup have this behavior :confused:

funny I just created a repro example and on the second read/setBean it removed the required label again

Lets see what this brings up