79439192

Date: 2025-02-14 11:23:01
Score: 0.5
Natty:
Report link

I know it's an old post, but I stumbled upon a similar conundrum.

I ended up wrapping a CheckboxSelectMultiple widget with a single choice inside a MultipleChoiceField. This allows the form to still be valid even without a return. I think this is an important aspect as the form.is_valid() method should be used to actually validate the form and not as a try-except substitute.

This worked for my application

 pseudo_checkbox= forms.MultipleChoiceField(
    choices=[('checked', 'Check Me')],
    widget=forms.CheckboxSelectMultiple(),
)

And having

checkbox = any(form.cleaned_data.get('pseudo_checkbox'))

In HTML, the multi checkboxes are treated as a list of checkboxes, so you can still change properties or apply functions to it.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: thekiroo