Deniz Dogan
Deniz Dogan

Reputation: 26227

ModelMultipleChoiceField validation acting differently depending on widget

I have a form with a ModelMultipleChoiceField and it works like a charm. However, when I set widget=forms.RadioSelect the form validation always fails with the error message "Enter a list of values."

As I said, it works perfectly well with the default widget, but not with the radio select widget. The POST request to validate the form is exactly the same, everything is exactly the same except for the widget, so I can't figure out what I'm doing wrong.

Why is this?

EDIT: Maybe I should have mentioned it works with CheckboxSelectMultiple as well.

EDIT2: It doesn't even seem to matter whether I set required=False, it still tells me to "enter a list of values."

Upvotes: 1

Views: 976

Answers (1)

Deniz Dogan
Deniz Dogan

Reputation: 26227

Wow, I was royally screwing up. Of course ModelMultipleChoiceField doesn't work with RadioSelect, because a list of radio buttons means that there can only be one single choice. The solution is to use ModelChoiceField.

Upvotes: 2

Related Questions