Skip to content

How to prepopulate the selected choices in HeavySelect2MultipleWidget and ModelMultipleChoiceField #4

Open
@rmControls

Description

@rmControls

Goal
How to pre populate multiple selected choices in HeavySelect2MultipleWidget and in ModelMultipleChoiceField

Problem
When form reloaded with validation error, all the pre selected choices will vanish for HeavySelect2MultipleWidget, ModelMultipleChoiceField
also not finding a way to pre populate the selected choices when you load update form...

Code Snippet

class RequestRegion(forms.Form):
    region = forms.ModelMultipleChoiceField(queryset=Region.objects.all().order_by('region_id'),
                                            widget=Select2MultipleWidget)

class CustReqForm(forms.Form):

    #CustomerField(widget=CustomerHeavyWidget(data_view = 'customer_ajax', attrs={'data-minimum-input-length': 4, 'delay':200}))
    distributor = forms.CharField(
            widget=HeavySelect2MultipleWidget(data_view='customer_ajax',
                                              attrs={'data-minimum-input-length': 4, 'delay':200},
                                              ), required=False #queryset=Customer.objects.none()
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions