Skip to content

Document the usage of widget.attrs #128

Closed
@raphodn

Description

@raphodn

Thanks for the package, it was really quick to set up.

It took me a bit of time (say 1h) to understand how to customize the placeholder & minimumInputLength options, without having to do any select2 javascript (and what I tried didn't work in any case).

I ended up finding the solution in an issue on the previous repo, and thought I could share it for future reference. And maybe add it to the documentation/examples somewhere ?

class MyForm(forms.Form):
    my_choice = forms.ModelMultipleChoiceField(
        widget=ModelSelect2MultipleWidget(
            model=MyOtherModel,
            search_fields=['title__icontains'],
            attrs={
                'data-placeholder': 'Custom placeholder',  // was empty
                'data-minimum-input-length': 0  // was 2
            }
        )
    )

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions