Opened 2 years ago

Closed 2 years ago

#33857 closed Bug (invalid)

using FilteredSelectMultiple widget on forms.ModelMultipleChoiceField is not working

Reported by: Sebastian Rossi Owned by: nobody
Component: Forms Version: 2.2
Severity: Normal Keywords: forms, widgets, ManytoMany, ModelMultipleChoiceField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Change History (1)

comment:1 by Mariusz Felisiak, 2 years ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top