Skip to content

Issues with TomSelectChoiceField or TomSelectIterablesWidget replacing a django ChoiceField #58

Description

@shortydutchie

Using 2026.3.3, python 3.12, django 5

I am trying to set up a simple ChoiceField with either TextChoices or a list of tuples to populate choices. This is to replace

self.fields["assay"] = forms.ChoiceField(choices=choices, required=True)

which gives me a usual dropdown with choices.

The following section with a django ChoiceField and a TomSelectIterablesWidget :

        from django.db.models import TextChoices
        class Status(TextChoices):
            DRAFT = 'D', 'Draft'
            PUBLISHED = 'P', 'Published'
            ARCHIVED = 'A', 'Archived'
        self.fields["assay"] = forms.ChoiceField(
            choices=Status.choices,
            required=True,
            widget=TomSelectIterablesWidget(
                config=TomSelectConfig(
                    plugin_dropdown_header=PluginDropdownHeader(
                        title="Select assay"
                    )
                )
            )
        )

gives rise to an error:

Reverse for 'autocomplete' not found. 'autocomplete' is not a valid view function or pattern name.

I tried setting url=None or url='' in the config, but this does not appear to work.

I also tried the dedicated TomSelectChoiceField, as follows (with and without a config)

        choices = zip(assaynameslist, assaynameslist)
        self.fields["assay"] = TomSelectChoiceField(
            choices=choices,
            required=True,
            #config=TomSelectConfig(
            #    url="",
            #    placeholder="Start typing to select an assay...",
            #),
        )

which gives rise to same error.
Is this a bug? I assumed it would use the supplied choices, rather than require an autocomplete url.

Any help appreciated!

PS - I have used TomSelectModelChoiceField and TomSelectModelMultipleChoiceField successfully, they work great (thank you for these).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions