In this case I must go through Heavy component and especially HeavySelect2MultipleWidget in order to have an input field in place of a select, otherwise, when 'tags' is added to js options it complains about requiring an input field.
class TrademarksTagsSelect2MultipleWidget(AutoHeavySelect2Mixin, HeavySelect2MultipleWidget):
def init_options(self):
super(TrademarksTagsSelect2MultipleWidget, self).init_options()
self.options['closeOnSelect'] = 'true'
self.options['tags'] = '[]' #-- Giving it an array with value changes nothing here...
self.options['tokenSeparators'] = '[",", " "]'
class TrademarkTagsField(AutoModelSelect2MultipleField):
search_fields = ['name__icontains', ]
queryset = Sale.trademarks_tags
widget = TrademarksTagsSelect2MultipleWidget
trademarks_tags = TrademarkTagsField()
The problem is that I can't create a new tag. Autosuggest works, select works but I don't find any way to create a new tag.
<script type="text/javascript">
$(function () {
$('#id_trademarks_tags').data('field_id', '0:2013-03-19 10:29:16.414892');$('#id_trademarks_tags').change(django_select2.onValChange).data('userGetValText', null);$("#id_trademarks_tags").select2({'tokenSeparators': '[",", " "]', 'initSelection': django_select2.onInit, 'multiple': true, 'minimumInputLength': 2, 'tags': '[]', 'closeOnSelect': 'true', 'ajax': {'dataType': 'json', 'quietMillis': 100, 'url': '/select2/fields/auto.json', 'data': django_select2.runInContextHelper(django_select2.get_url_params, 'id_trademarks_tags'), 'results': django_select2.runInContextHelper(django_select2.process_results, 'id_trademarks_tags')}, 'separator': django_select2.MULTISEPARATOR});
});
</script>