[Django] #33857: using FilteredSelectMultiple widget on forms.ModelMultipleChoiceField is not working

396 views
Skip to first unread message

Django

unread,
Jul 18, 2022, 1:43:38 PM7/18/22
to django-...@googlegroups.com
#33857: using FilteredSelectMultiple widget on forms.ModelMultipleChoiceField is
not working
-------------------------------------+-------------------------------------
Reporter: SebaRGFSL | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 2.2
Severity: Normal | Keywords: forms, widgets,
| ManytoMany,
Triage Stage: | ModelMultipleChoiceField
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello there,
I have a form which has a ModelMultipleChoiceField in it, that works
correctly, but when i try to add the FilteredSelectMultiple widget from
the admin widgets somehow the selected values are no longer in the payload
of the POST request

Here is the piece of code for the form field


{{{
class Media:
css = {
'all': ('/static/admin/css/widgets.css',),
}
js = ('/admin/jsi18n',)

dental_codes = forms.ModelMultipleChoiceField(
label='Select Proccedure Codes',
queryset = CDTADACodes.objects.all(),
widget = FilteredSelectMultiple('Dental Codes Selection',
is_stacked=True),
required = False
)
}}}

Here is the html template


{{{
<div class="row justify-content-md-center">
<div class="form-group">
{{form.media}}
{{form.dental_codes.errors}}
{{form.dental_codes}}
</div>
</div>
}}}

Template is correctly loaded in Front End but no values are selected when
used. Only by commenting the widget assignment sentence the code works
correctly.

Any help is welcomed, thanks in advance

--
Ticket URL: <https://code.djangoproject.com/ticket/33857>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 18, 2022, 2:25:30 PM7/18/22
to django-...@googlegroups.com
#33857: using FilteredSelectMultiple widget on forms.ModelMultipleChoiceField is
not working
-------------------------------------+-------------------------------------
Reporter: SebaRGFSL | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 2.2
Severity: Normal | Resolution: invalid
Keywords: forms, widgets, | Triage Stage:
ManytoMany, | Unreviewed
ModelMultipleChoiceField |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

It works for me in the admin, so it's probably an issue in your code. I
used the following form:
{{{
class MyBrushForm(forms.ModelForm):


dental_codes = forms.ModelMultipleChoiceField(
label='Select Proccedure Codes',

queryset = DentalCode.objects.all(),


widget = FilteredSelectMultiple('Dental Codes Selection',
is_stacked=True),

required = False,
)
code = forms.IntegerField()

class Meta:
model = Brush
fields = ['code', 'dental_codes']


class BrushAdmin(admin.ModelAdmin):
form = MyBrushForm
}}}

Moreover Django 2.2 is not supported anymore, you can try to use Django
4.0+.

See TicketClosingReasons/UseSupportChannels for ways to get help.

--
Ticket URL: <https://code.djangoproject.com/ticket/33857#comment:1>

Reply all
Reply to author
Forward
0 new messages