Score:0

How can I uncheck checkbox fields during form's validation?

ng flag

We have a Drupal 9 custom validaton hanlder where we need to remove all checkboxes from a multi-value term reference field.

I can clear/change other field types but not this one.

We tried the following code, and other variations.

  $form_state->setValue('field_region', []);

The values always retain even though getValue() for the field shows as cleared in the validation function.

Do you have any idea?

4uk4 avatar
cn flag
When I set the field to an empty array it unchecks all checkboxes on the saved entity, for a reference field configured with the *Check Boxes* widget. To find the error I think you need to look into the variables. Things might be different in your form. The loop by the way has no function, as the code is written now you can remove it.
quantumized avatar
ng flag
@4uk4 - thank you. Yep, that loop for part of another attempt. I've removed it and the values still do not clear when uses in a custom validator. I've updated the question. Any ideas?
quantumized avatar
ng flag
@4uk4 - crap, should have noted that we're testing with the "preview" function which runs the validator but doesn't seem to save the cleared values to the form when returning from the preview.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.