django search form

Hello there

I want to create a form with CreateView and I’d like to insert specific choices for a field. When I use choices field option I end up with an enormous list of choices for the user. I’d like to filter that list when the user writes sth in the form. (e.g. when the user writes ‘a’, the list must contain only the choices starting from a). Is it possible with django?
Thanks in advance

Is it possible with django?

Kind of.

You can either have another view for filtering choices and make periodic requests with JavaScript to update the filter or you can do this via JavaScript only on the page. You would observe input on the first field and use it to filter the list.

Let us know which option you would prefer so we can assist further here :slight_smile:

Thanks a lot for the answer. I wanted to know if it could be done without js. I will insert a js file after class Meta: and I’ll do it with js. Thanks a lot and have a nice day

Correct, this cannot be done without JavaScript.

For a head-start on this, see the Select2 and Django-select2 projects. They may be enough for what you need.

thanks a lot … it was really helpfull