applegrew / django-select2

This is a Django integration for Select2
MIT License
710 stars 316 forks source link

Disable multiple select on tag widget #602

Closed Ardillen66 closed 4 years ago

Ardillen66 commented 4 years ago

The default implementation of Select2TagWidget and its children is a MultipleSelect. This seems to exclude regular (single) select2 widgets, and it is not clear if this is possible and how from the documentation.

I can see two solutions to this issue.

Either make additional classes for tag widgets. However I understand this would require some more work, as there would need to be Select2TagWidget, HeavySelect2TagWidget and ModelSelect2TagWidget variants for this.

Alternatively, updating the documentation with a note that indicates how to configure a single select widget. I have done this myself by simply setting allow_multiple_selected = False, but I need to do some more testing to check if this is sufficient. From the Django source code it seems relatively easy, as only value_from_datadict and value_omitted_from_data are overridden by the multiple select widget.

Which do you thinks would be best? If you agree I can make a pull request for either solution.

codingjoe commented 4 years ago

@Ardillen66 thanks for reaching out. I see your point, I supposed this could be solved either way. Which one to you prefer? I personally don't see a huge use case for a single tag widget, but you, writing this ticket may prove me wrong. Just out of curiosity, what is your use case? Best, Joe

Ardillen66 commented 4 years ago

Hi Joe, thanks for the quick reply. I want to use the tag functionality to allow users to either select an existing model with the select2 widget or to create a model by writing a string that can be parsed and used to create a new instance.

Ardillen66 commented 4 years ago

For the approach I think the first option is cleaner and more in line with proper object oriented design.

codingjoe commented 4 years ago

I see, does the model consist of more than a string and a surrogate primary key?

codingjoe commented 4 years ago

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