Opened 9 years ago
Last modified 9 years ago
#25980 new Bug
Wrong handling of initial value on disabled ModelMultipleChoiceField — at Version 3
Reported by: | karyon | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | johannes.linke@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
So i provided a queryset as initial value for a non-required and disabled ModelMultipleChoiceField. it seemed to work as i saw the correct values in the rendered output.
but, when saving the form i got an error Enter a list of values.
- this happens because disabled fields send their initial value to cleaning, see [here. in case of model fields, it looks like this must be a list of PKs, which is quite unhandy to build (something like
list(queryset.values_list('pk', flat=True))
) - the error did not show up when the queryset i provided yielded no results, which is inconsistent. the reason for that is that this boolean expression evaluates to true as soon as there are results in the queryset.
- something else appeared fishy to me: in one line the clean method returns a queryset (
self.queryset.none()
), but in the next line it raises an error if the value is neither a list nor a tuple.
if you folks tell me what the intended behaviour is / which types should be used, i can try to create a fix if you want.
- and the last (slightly unrelated) issue: since the field was disabled, i was wondering why cleaning it doesn't take a shortcut and does nothing at all... bumped into this a few times.
Change History (3)
comment:1 by , 9 years ago
Cc: | added |
---|
comment:2 by , 9 years ago
Description: | modified (diff) |
---|
comment:3 by , 9 years ago
Description: | modified (diff) |
---|---|
Summary: | Inconsistent error behaviour when providing a queryset as initial value on ModelMultipleChoiceField → Wrong handling of initial value on disabled ModelMultipleChoiceField |
Note:
See TracTickets
for help on using tickets.