applegrew / django-select2

This is a Django integration for Select2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

We should add documentation regarding widget configuration

ArionMiles opened this issue · comments

I am using this project for a side project and I wanted to add maximumSelectionLength attribute to my Select2MultipleWidget, and I was scouring through the docs and found nothing. I tried to edit the django_select2.js static file in /static/django_select2/ (I know, hacky, but I was out of options 😛)

A complete reference of Select2's config is available here: https://select2.org/configuration/options-api

Though, I think a minor difference is the config we provide to django_select2 must begin with data- and the config name must be lowercase, with each word separated by a hyphen.

So maximumSelectionLength becomes data-maximum-selection-length

Then I found out I had to provide a dict of config like Select2MultipleWidget({'data-maximum-selection-length': 5}) to make it work.

I'd like to add a documentation page regarding configuring widget attributes so that it'll be a good reference for the future and help others, too.

@ArionMiles very good point! I would very much welcome a pull-request from you adding a couple lines on how to customize the JS behavior and pass configuration via data attributes.

Apart from the config reference I've linked in my initial message, are there other config properties I'm missing and should know about?

There are also no instructions on how to modify the Language (and Translation objects) of select2, like the JS libary supports here: https://select2.org/i18n#translation-objects

if you could tell me here, I'd love to add them in the docs

@ArionMiles I think it's a very good start. I guess we also need to document, how to overwrite the actual JavaScript code, like it's done here #561 (comment)
But that would be part 2, I guess.

I recently made use of django-select2 and as a beginner I have to say I'm quite lost. It could be really helpful if the guide covered more aspects of the configuration, such as establishing the language of the widgets, or as @ArionMiles already stated, setting select2 configuration parameters. I'm trying to follow his advice but I'm getting no result. I have such a narrow Select2Widget and I'm trying to customize it in forms.py without success.

Oh man I forgot about this! I'll try making a draft PR ASAP.

Thanks @ArionMiles, in the meanwhile, could you lend me a hand on how to set the width of the Select2Widget (not the model one) via the python code? Is it possible or do I have to do it via css?
Also, where do I have to specify the language of the widgets?
Thanks again for your work!

Could you create a separate issue?

Sure thing! Done! @ArionMiles

This repo has moved, please address your issue at https://github.com/codingjoe/django-select2 Thanks!