Opened 22 months ago

Last modified 22 months 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="{{ }}">

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:

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 Changed 22 months ago by cloudy-sfu

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