Why is the data-tags attribute not preserved in my Django form widget? autoComplete DAL Select2

I'm using a CharField with a custom widget (ListSelect2) from the django-autocomplete-light library. I have a set of data-* attributes, including data-tags, that I want to be passed to the HTML output, but it doesn't seem like the data-tags attribute is being preserved or rendered correctly in the final after form is saved.

industry_type = forms.CharField(
    widget=autocomplete.ListSelect2(
        url='/career-listings/industry-autocomplete/',
        attrs={
            'class': 'w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition duration-200',
            'data-placeholder': 'Industry',
            'data-minimum-input-length': 1,
            'data-theme': 'tailwindcss-3',
            'data-tags': 'true',  # The attribute I'm trying to preserve
            'id': 'id_industry_type',
        },
        forward=['name'],
    ),
    required=True,
)

What happens instead: The data-tags attribute does not appear in the HTML after form is saved. The field

Things I've tried: I added data-tags to the attrs dictionary of the widget.

I ensured that the widget is being properly rendered in the template. The data only data-tags is not preserved on form is submitted.

Back to Top