Simple Ajax Search

141 views
Skip to first unread message

lone...@gmail.com

unread,
Nov 23, 2023, 7:36:23 AM11/23/23
to Django users
Hello all,

   I am looking for a simple how-to on creating an interactive search on a text field.  As the user types the search results change and the user can click on the search result that they want.  I have installed jquery3 and bootstrap5 in my django project.

Thank you.

Thomas Couch

unread,
Nov 23, 2023, 9:09:11 AM11/23/23
to Django users
I think Select2 is a well trodden path for this sort of thing (unless I'm mistaken, it's already available in the admin interface). Have a look at the django-select2 package: https://django-select2.readthedocs.io/en/latest/

lone...@gmail.com

unread,
Nov 23, 2023, 9:20:37 AM11/23/23
to Django users

A stipulation that I forgot to mention is that the desired drop down selections will be coming from an external API. I did not see the package calling out to an external API, will this still work?

Thomas Couch

unread,
Nov 23, 2023, 9:28:52 AM11/23/23
to Django users
Yeah it's doable. Just had a quick look and that package has a HeavySelect2Widget for ajax requests: https://django-select2.readthedocs.io/en/latest/django_select2.html#django_select2.forms.HeavySelect2Widget

Alternatively, forget about the Django package and just use select2 directly: https://select2.org/

raghav bajaj

unread,
Nov 23, 2023, 10:10:24 AM11/23/23
to django...@googlegroups.com
You can make an AJAX call using the oninput event of the search input field. Use a GET method to fetch the results from the DB in the AJAX call.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6bc300c2-1d1f-4e87-90bb-1311e2120c77n%40googlegroups.com.


--
Raghav Bajaj
Cell: +91 7420889933

Kwarteng

unread,
Nov 25, 2023, 8:29:01 PM11/25/23
to Django users
you can try typeahead.js

Mithilesh Rawani

unread,
Nov 25, 2023, 9:49:55 PM11/25/23
to django...@googlegroups.com
Mithilesh rawani software developer deoghar Jharkhand

Reply all
Reply to author
Forward
0 new messages