Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:55:10+00:00 2026-06-10T18:55:10+00:00

I was trying to dynamically generate fields as shown in http://jacobian.org/writing/dynamic-form-generation/ . My case

  • 0

I was trying to dynamically generate fields as shown in http://jacobian.org/writing/dynamic-form-generation/. My case slightly differs in that I am looking to use multiplechoicefield that is dynamically created. This is what I came up with…

views.py

def browseget(request):
    success = False
    if request.method == 'POST':
        list_form = ListForm(request.POST)
        if list_form.is_valid():
            success = True
            path = list_form.cleaned_data['path']
            minimum_size = list_form.cleaned_data['minimum_size']
            follow_link = list_form.cleaned_data['follow_link']
            checkboxes = list_form.cleaned_data['checkboxes']
            ....do something
    else:
        list_form = ListForm(name_list)
    ctx = {'success': success, 'list_form': list_form, 'path': path, 'minimum_size': minimum_size}
    return render_to_response('photoget/browseget.html', ctx, context_instance=RequestContext(request))

forms.py

class ListForm(forms.Form):
    path = forms.CharField(required=False)
    minimum_size = forms.ChoiceField(choices=size_choices)
    follow_link = forms.BooleanField(required=False, initial=True)

    def __init__(self, *args, **kwargs):
        name_list = kwargs.pop('name_list', None)
        super(ListForm, self).__init__(*args, **kwargs)
        print 'Received data:', self.data
        if name_list:
            name_choices = [(u, u) for u in name_list]
            self.fields['checkboxes'] = forms.MultipleChoiceField(required=False, label='Select Name(s):', widget=forms.CheckboxSelectMultiple(), choices=name_choices)

    def clean_path(self):
        cd = self.cleaned_data
        path = cd.get('path')
        if path == '': path = None
        return path

    def clean_minimum_size(self):
        cd = self.cleaned_data
        minimum_size = cd.get('minimum_size')
        if minimum_size is None: minimum_size = 0
        return int(minimum_size)

The form generates and displays perfectly… until I post some data. The ‘checkboxes’ field doesn’t show up in list_form.cleaned_data.items() while it shows in self.data. As it is the form breaks with a KeyError exception. So Im asking, how do i access the checkboxes data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:55:11+00:00Added an answer on June 10, 2026 at 6:55 pm

    You’re not passing in the name_list parameter when you re-instantiate the form on POST, so the field is not created because if name_list is False.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass dynamically created form fields to a php script, and
Hello I'm trying to dynamically generate some inputs for my form, but it's not
I'm trying to dynamically generate a new Model, based on fields from an existing
I am currently writing a Python script and trying to dynamically generate some arguments.
I am trying to dynamically generate an XSLT document from an XSLT stylesheet. In
I'm trying to dynamically generate QR codes for my thermal printer. In order to
There is one problem occurring when I am trying to dynamically generate the label
I am trying to have my interface dynamically generate a customized button when I
I am trying to generate a gridview dynamically through codebehind. So I am making
I'm trying to generate a list dynamically from database. The results can be retrieved,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.