Opened 3 years ago

Last modified 3 years ago

#33042 closed Cleanup/optimization

Form validator cannot pass ModelMultipleChoiceField by checkbox — at Version 1

Reported by: cloudy-sfu Owned by: cloudy-sfu
Component: Forms Version: 3.2
Severity: Normal Keywords: form, validator, widget
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by cloudy-sfu)

In the form, I set:

fill_na_avg = forms.ModelMultipleChoiceField(Column.objects.all(), widget=forms.HiddenInput(), required=False)

In the HTML file, I write a group of :

<input type="checkbox" name="fill_na_avg" value="{{ column.id }}">

After submitting the POST, there is:

<QueryDict: {'fill_na_avg': ['41', '42', '43']}>

It seems normal but when checking it by the "is_valid" function, it reports:

fill_na_avg
Enter a list of values.

If I remove widget setting like:

fill_na_avg = forms.ModelMultipleChoiceField(Column.objects.all(), required=False)

It works. So, why widget affects the validation of forms?

Change History (1)

comment:1 by cloudy-sfu, 3 years ago

Description: modified (diff)
Keywords: widget added; checkbox removed
Owner: changed from nobody to cloudy-sfu
Status: newassigned
Type: BugCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top