Reputation: 15453
How do I get the selected value from a form's ComboBox field? what is the model class that deals with ComboBoxes? ..
Thanks.
Upvotes: 2
Views: 7047
Reputation: 185
As mentioned by @MMRUser, the ChoiceField
is the form class to achieve an HTML select
element.
But for the model itself, you can pass the choices argument to a model field (typically a CharField
) which will result in the ModelForm
using an HTML select
element.
Upvotes: 1
Reputation: 599630
There's no such thing as a ComboBox in Django (or in HTML). I assume you are talking about a ChoiceField
, which renders a select
control in HTML.
You access the value of a ChoiceField in exactly the same way as any other field, once the form has been submitted and validated - by accessing form.cleaned_data['fieldname']
.
You should read the excellent documentation on forms.
Upvotes: 5