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

  • Home
  • SEARCH
  • 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 7217941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:25:03+00:00 2026-05-28T21:25:03+00:00

Say I have two types of objects, Apples and Chainsaws . A user is

  • 0

Say I have two types of objects, Apples and Chainsaws. A user is presented with a form and the first field asks them which object they would like to purchase. If they select ApplesI would like one select form field to dynamically appear with options green and red and a label of color. On the other hand, if they select Chainsaws I would like two form fields to dynamically appear, one being a CharField with a label of Your Name and the second being an IntegerField with a label of Your Age (it’s a good idea to keep track of who’s buying your chainsaws).

This, of course, is just an example. The main idea is that I would like to be able to dynamically choose the number and types of fields as well as the data in the fields depending on the user selecting an option from an initial select list…using Django templates. I’ve found plenty of tutorials and questions related to dynamically populating a select list or adding additional fields of a homogeneous type (e.g. additional file upload fields), but I can’t seem to figure out how to dynamically add/change the attributes of my form.

Thanks for any help!
-C

  • 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-05-28T21:25:04+00:00Added an answer on May 28, 2026 at 9:25 pm

    The short answer is that this requires a mixture of CSS, javascript and django forms.

    The Form

    Step 1 is create a form with conditional validation se my clean method.

    from django import forms
    from django.utils.translation import ugettext as _
    from django.forms.widgets import RadioSelect, Textarea, CheckboxSelectMultiple
    from django.utils.safestring import mark_safe
    
    class FormContact(forms.Form):
        """
        The contact form
        """
        choice_a = forms.ChoiceField(
            label=_(u' '),
            choices=(
                (1, mark_safe(_(u'First Option'))),
                (0, mark_safe(_(u'Second Option'))),
            ),
            widget=RadioSelect,
            initial=1
        )
        show_if_choice_1 = forms.CharField(
            label=_(u'Choice 1 text box')
        )
        show_if_choice_2 = forms.CharField(
            label=_(u'Choice 2 text box')
        )
    
        def clean(self):
            super(forms.Form, self).clean()
    
            if 'choice_a' in self.cleaned_data :
                if self.cleaned_data['choice_a'] == '1':
                    if self.cleaned_data['show_if_choice_1'] == '' :
                        self._errors['show_if_choice_1'] = self.error_class([_(u'Please Fill out choice 1 text box.'),])
                if self.cleaned_data['choice_a'] == '2':
                    if self.cleaned_data['show_if_choice_2'] == '' :
                        self._errors['show_if_choice_2'] = self.error_class([_(u'Please fill out choice 2 box'),])
    
            return self.cleaned_data
    

    The JS and CSS

    write some javascript + CSS to show hide fields based on the value of the conditional field.

    Note: If you need more direction please just tell me, I didn’t want to spend an eternity typing if you got the jist quickly.

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

Sidebar

Related Questions

Let's say I have a GUI with multiple types of viewers of user objects.
In my NSArray, I have two types of objects, let's say objects of class
I have a two generic abstract types: Entity and Association . Let's say Entity
Let's say you have two objects (for example, a UITextviews, but it could be
I have two IQueryable<> lists. Say one is filled with objects of Class Bottle
Say if I have two different types of sensors: one monitors analog voltage (such
Let's say I have two string objects: 25000.00, and 1234 that my program gets
I have a list of custom objects: say Fruits with two string properties Name
Lets say we have two defined function objects add1 = lambda x: x+1 and
A little question about creating objects. Say I have these two classes: struct A{

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.