ComboBox

44 views
Skip to first unread message

Phil Parkin

unread,
May 31, 2022, 4:07:14 PM5/31/22
to Django users
Hi all

I am converting a desktop application to Django web application. The desktop app uses comboboxes (editable dropdown/select). Is their any elegant way of applying the same functionality in Django? Stack Overflow etc. all seem to be about dropdown select lists only.

I can see ways of doing this with a Choicefield plus a separate Charfield, but is there a better way?

Thanks -Phil 

Roger Gammans

unread,
Jun 1, 2022, 4:13:11 AM6/1/22
to django...@googlegroups.com
Hi

If any arbitrary text is allowable, then at the model level I'd just use a CharField. I wouldn't add a choices= argument to the field unless is the value is strictly constrained to those choice as other test would then fail validation.

At the Form level, I'm not sure. I'd probably work just mirror what the frontend needed.

Does that help ?
--
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/1b7836ae-e52e-4e35-aefc-739ce6f586d0n%40googlegroups.com.

Ryan Nowakowski

unread,
Jun 4, 2022, 5:31:54 PM6/4/22
to django...@googlegroups.com
The HTML element you probably want is a datalist[1]. There's no built-in Django support for datalist[2] so you'll probably need to create a custom widget.

[1] https://stackoverflow.com/a/14614750
[2] https://code.djangoproject.com/ticket/32125

Phil Parkin

unread,
Jun 5, 2022, 5:58:07 AM6/5/22
to Django users
Thanks for the responses. 
rgam - I appreciate what you are saying. I think it is roughly what I am doing now, but it is a bit clumsy in that  the user (of a financial application) will typically have a list of regular  customers to select from, and also may have other customers that are one-off, or infrequent which they will not want to clutter their options list with but still need to record against a transaction.
Ryan - thanks, the datalist looks like it might be right option. I will look at custom widgets.

All the best - Phil
Reply all
Reply to author
Forward
0 new messages