Questions tagged [choicefield]

202 questions
82
votes
10 answers

How to get the label of a choice in a Django forms ChoiceField?

I have a ChoiceField, now how do I get the label when I need it? class ContactForm(forms.Form): reason = forms.ChoiceField(choices=[("feature", "A feature"), ("order", "An order")], …
webjunkie
  • 6,891
  • 7
  • 46
  • 43
48
votes
4 answers

Django ChoiceField

I'm trying to solve following issue: I have a web page that can see only moderators. Fields displayed on this page (after user have registered): Username, First name+Last name, Email, Status, Relevance, etc. I need to display table with information…
Denis
  • 499
  • 1
  • 5
  • 10
29
votes
5 answers

Translate select options in Symfony2 class forms

I'm using a class form in Symfony2 Beta3 as follows: namespace Partners\FrontendBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class ConfigForm extends AbstractType { public function…
Sergi
  • 1,224
  • 3
  • 15
  • 34
24
votes
2 answers

Django populate a form.ChoiceField field from a queryset and relate the choice back to the model object

I have a simple form: class SubmissionQuickReplyForm(forms.Form): comment_text = forms.CharField(label='', required=False, widget=forms.Textarea(attrs={'rows':2})) I want to add a form.ChoiceField to the form, where the options in the…
43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
18
votes
5 answers

Django ChoiceField populated from database values

I am having problems using a ChoiceField to create a drop down list of values in the database. Here is the snippet of code from django import forms from testplatform.models import ServiceOffering class ContactForm(forms.Form): subject =…
Oli
  • 2,267
  • 5
  • 22
  • 21
16
votes
4 answers

Django: Filter for get_foo_display in a Queryset

I've been trying to filter a queryset on a simple model but with no luck so far. Here is my model: class Country(models.Model): COUNTRY_CHOICES = ( ('FR', _(u'France')), ('VE', _(u'Venezuela')), ) code =…
jtheoof
  • 585
  • 6
  • 10
12
votes
3 answers

Symfony choice field type reports "This value is not valid" when submitting an invalid option. How do I change this?

I've noticed that when using the Symfony 2.3 choice field type, if I try to submit an invalid option (by manually changing the value of an option), symfony reports a form error on that field that says "This value is not valid". However, I see no…
user3009816
  • 797
  • 2
  • 8
  • 16
11
votes
1 answer

Symfony 2 : Get available choices of a choice Field Type

1) Is there a symfony method ? I've got a basic form (not mapped to the database), with some choice fields, for example : $builder->add('civility', 'choice', array('choices'=> array('m' => 'M.', 'mme' => 'Mme', 'mlle' => 'Mlle'))) How can I -…
Bonswouar
  • 1,521
  • 2
  • 17
  • 37
9
votes
2 answers

Allow all value on choice field type in Symfony2 form builder

I have a problem for a while and I have read a lot on this topic with similar problem but cant implement the answers in my case. I have a select field that I populate with Ajax. so in my form builder I have this code : VilleType.php /** *…
LedZelkin
  • 586
  • 1
  • 10
  • 24
9
votes
1 answer

Using dynamic Choice Field in Django

I have a choiceField in order to create a select field with some options. Something like this: forms.py class NewForm(forms.Form): title = forms.CharField(max_length=69) parent = forms.ChoiceField(choices = CHOICE) But I want to…
r_31415
  • 8,752
  • 17
  • 74
  • 121
8
votes
4 answers

Django ORM, how to use values() and still work with choicefield?

I am using django v1.10.2 I am trying to create dynamic reports whereby I store fields and conditions and the main ORM model information into database. My code for the generation of the dynamic report is class_object = class_for_name("app.models",…
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
8
votes
4 answers

How to use a choiceField declared in the model, in a form. django

I have this in my model.py class marca(models.Model): marcas = ( ('chevrolet', 'Chevrolet'), ('mazda', 'Mazda'), ('nissan', 'Nissan'), ('toyota', 'Toyota'), ('mitsubishi', 'Mitsubishi'), ) marca =…
Hugo Montoya
  • 93
  • 1
  • 2
  • 4
7
votes
2 answers

Django Form ChoiceField range(): 'int' object not iterable

from django import forms class SignUpForm(forms.Form): birth_day = forms.ChoiceField(choices=range(1,32)) I'm getting "Caught TypeError while rendering: 'int' object is not…
deadghost
  • 5,017
  • 3
  • 34
  • 46
7
votes
1 answer

Django - ChoiceField cleaned_data gets String instead of Integer

I have a form field called 'units' like this: units = forms.ChoiceField(choices=[(x, x) for x in range(1, 11)], help_text = 'Units: ') When I do form.cleaned_data['units'] I get a String instead of an Integer. How can I change the field to get…
Jorge Cámara
  • 343
  • 2
  • 9
7
votes
2 answers

Symfony3 : choice type field filled with array of objects

I have an entity Product. My product can have multiple names in different languages. A name in french, a name in english, etc. I don't want to use an automatic translation. The user will have to write the names in the Product form and select the…
Eve
  • 776
  • 2
  • 11
  • 32
1
2 3
13 14