0

Here's my forms.py:

from django import forms
from users.models import EnglishInterest, UserPlans

class CLSelectionForm(forms.Form):

    plan_choices = UserPlans().get_plan_choices_active()
    englishInterest_choices = EnglishInterest().get_english_interest_active()

    useremail = forms.EmailField(widget=forms.HiddenInput(attrs={
        'type': 'email'}))
    coupon = forms.CharField(widget=forms.HiddenInput(attrs={
        'type': 'email'}))

    plans = forms.CharField(label='Plan Choice',
                        widget=forms.Select(choices=plan_choices, attrs={'id': 'plan_choice', 
              'class': 'fs-anim-lower fs-select-box', 'name': 'plan_choice'}))
    englishInterest = forms.CharField(
        label='English Interest', widget=forms.Select(choices=englishInterest_choices, attrs={'id': 
         'english_choice', 'class': 'fs-anim-lower fs-select-box', 'name': 'english_choice'}))

    submitButton = forms.CharField(widget=forms.TextInput(
        attrs={'type': 'submit', 'name': 'submit', 'id': 'fs-submit-button', 'class': 'fs-submit', 
         'value': 'Submit'}))

    class Meta:
        fields = ['useremail', 'coupon', 'plans', 'englishInterest']

How would I go about rendering the plans and englishInterest form elements, with options that include a selected attribute?

Lawrence DeSouza
  • 984
  • 5
  • 16
  • 34
  • set an initial value for the field. see the doc: https://docs.djangoproject.com/en/2.2/ref/forms/fields/#initial – bmons Nov 24 '19 at 05:29
  • But can you set an initial value from the view? This form is going to take POST data from another form, and set that initial value. – Lawrence DeSouza Nov 24 '19 at 07:56
  • check out this https://stackoverflow.com/questions/7871488/django-initial-value-of-choicefield – bmons Nov 24 '19 at 08:11

0 Answers0