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 8205161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:07:50+00:00 2026-06-07T08:07:50+00:00

I am currently making a template in Django that renders some forms. I have

  • 0

I am currently making a template in Django that renders some forms. I have multiple profile models that hold specific data based on what type of user the user is. For example I have a Corporate profile that holds a company name and a Customer profile that holds a personal phone number. I have a ChoiceField that I am using to determine which type of user is filling out the form and based on what the user selects I display a set of specific fields. When the user makes a selection I’m using JQuery to make the specific hidden fields visible.

The problem I am running into is that some of the fields that do not get displayed are required for the other model. So lets say the company name is required for the Corporate profile and the personal phone number is required for the Customer profile. If the user selects Corporate as their type my template returns errors for the personal phone number field and does not submit. Is there a way with Django, JQuery, or something else to disable or remove or ignore the unnecessary fields based on the user selection?

Here is how I am currently hiding the info:

<script type="text/javascript">
$(document).ready(function() {
$("#id_user_type").change(function(){
    $(".user-type-wrapper").slideUp('500');
    $("#user-type-"+$(this).val()).slideDown('500');
});});
</script>

This script is affecting this portion of my template:

 ...
 <div class="field">
     {{ form.user_type.errors }}
     <label for="id_user_type">User Type:</label>
     {{ form.user_type }}
 </div>

 <!-- Company Specific Form Content -->
 <div class="user-type-wrapper" id="user-type-CO" style="display: none;">
      <div class="field">
          {{ form.company_name.errors }}
          <label for="id_company_name">Company Name:</label>
          {{ form.company_name }}
      </div>
 </div>
 <!-- End Company Specific Form Content -->

 <!-- Customer Specific Form Content -->
 <div class="user-type-wrapper" id="user-type-CU">
      <div class="field">
          {{ form.phone_number.errors }}
          <label for="id_phone_number">Phone Number:</label>
          {{ form.phone_number }}
      </div>
 </div>
 <!-- End Customer Specific Form Content -->
 ...

Any help would be greatly appreciated!

  • 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-07T08:07:52+00:00Added an answer on June 7, 2026 at 8:07 am

    Implementation

    After some searching I was able to come up with a solution. I added Dajax to my implementation to reload the page with the required fields based on what type of user the user selected. This enabled me to eliminate the fields that didn’t need to be completed and still perform validation on the ones that did.

    Further Reading

    To help anyone else that’s having a similar problem I would recommend checking out the Dajax Project, especially the Pagination Example. I ran into some issues by just following the tutorial but if you visit the Dajax Github Repo you should be able to get through it.

    Issues To Watch For

  2. If you are using JQuery UI insure that you load the JQuery version of Dajax and not the Prototype version. Loading Prototype will result in the JQuery not functioning on the pages that you load the Dajax links in. For reference see the import code located at https://github.com/jorgebastida/django-dajax/issues/37.
  3. If you are using JQuery make sure to include the following in your header:
  4. <script src="https://github.com/cowboy/jquery-misc/blob/master/jquery.ba-serializeobject.js" type="text/javascript" charset="utf-8"></script>
    

    This is listed in the documentation if you search for it but is easy to overlook

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

Sidebar

Related Questions

Currently making a global volunteer site, and the webpages will more or less have
I'm currently making an application with Backbone.js and some JQuery libraries. Today I work
I am currently making a program that will send an email if the date
I am currently making an Android launcher and have spent a lot of time
I've got a view in Django that uses memcached to cache data for the
Currently, I'm in the process of making a custom solution for invoicing. I have
I'm currently making a server dashboard that relies quite heavily on graphs and charts.
I'm currently dealing with a string initialized in main() that for some reason freaks
I'm currently having a problem with a class template in C++. I'm currently making
I'm making a template that is relying on a lot on a tabbed interface

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.