Opened 4 years ago
Closed 4 years ago
#33042 closed Cleanup/optimization (invalid)
Form validator cannot pass ModelMultipleChoiceField by checkbox
| 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 )
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 (2)
comment:1 by , 4 years ago
| Description: | modified (diff) |
|---|---|
| Keywords: | widget added; checkbox removed |
| Owner: | changed from to |
| Status: | new → assigned |
| Type: | Bug → Cleanup/optimization |
comment:2 by , 4 years ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
You must use a widget that supports multiple values, e.g.
MultipleHiddenInputorSelectMultiple. If you're having trouble understanding how Django works, see TicketClosingReasons/UseSupportChannels for ways to get help