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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:43:29+00:00 2026-06-03T03:43:29+00:00

Form HTML <form action= method=post class=form-horizontal><div style=display:none><input type=hidden name=csrfmiddlewaretoken value=6b3d58df7bd4f6d10975462aaf3bd42d></div> <input type=hidden name=paper value=5225

  • 0

Form HTML

<form action="" method="post" class="form-horizontal"><div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="6b3d58df7bd4f6d10975462aaf3bd42d"></div>
        <input type="hidden" name="paper" value="5225" id="id_paper"><fieldset><div id="div_id_priority" class="control-group">
    <label class="control-label" for="id_priority">Priority</label>
    <div class="controls">
        <select name="priority" id="id_priority">
<option value="1" selected="selected">Primary</option>
<option value="2">Secondary</option>
</select>


        <p class="help-block"><span class="help_text">Primary - 1st Choice. Secondary - 2nd Choice.</span></p>

    </div>
</div> <!-- /clearfix -->
<div id="div_id_topic" class="control-group">
    <label class="control-label" for="id_topic">Topics</label>
    <div class="controls">
        <select name="topic" id="id_topic">
<option value="6">A</option>
<option value="7" selected="selected">B</option>
<option value="9">C</option>
</select>


    </div>
</div> <!-- /clearfix -->
<div id="div_id_subtopic" class="control-group error">
    <label class="control-label" for="id_subtopic">SubTopics</label>
    <div class="controls">
        <select name="subtopic" id="id_subtopic">
<option value="29">KEEPER</option></select>

        <span class="help-inline">Select a valid choice. 29 is not one of the available choices.</span>


    </div>
</div> <!-- /clearfix -->
</fieldset>

        <div class="form-actions">
            <button type="submit" class="btn btn-primary">Add</button>
        </div>

    </form>

VIEW

@login_required
@event_required
def add_topic(request, paper_id):
    event = request.event
    paper = get_object_or_404(SubmissionImportData, pk=paper_id)
    form = TopicForm(request.POST or None, event=event, paper=paper)
    print request.POST  # i see subtopic here
    print form.errors
    if request.method == 'POST' and form.is_valid():
        cd = form.cleaned_data
        subtopic = request.POST.get('subtopic')
        if subtopic:
            subtopic_obj = get_object_or_404(SubTopic, pk=subtopic)
        else:
            subtopic_obj = None

        paper_topic = PaperTopic.objects.get_or_create(
                submission_import_data=paper,
                priority=cd['priority'],
                topic=cd['topic'],
                sub_topic=subtopic_obj)[0]

        msg = 'Topic Successfully Added'
        messages.success(request, msg)
        url = reverse('submissions_nonadmin_view_topic',
                args=[event.slug, paper.id])
        return redirect(url)

FORM CLASS

class TopicForm(BootstrapForm):
    topic = forms.ModelChoiceField(label='Topics',
            queryset=None, required=False, empty_label=None)
    subtopic = forms.ChoiceField(label='SubTopics',
            widget=forms.Select(attrs={'disabled': 'disabled'}),
            required=False)
    paper = forms.IntegerField(widget=forms.HiddenInput())
    priority = forms.ChoiceField(label='Priority',
            choices=PaperTopic.PRIORITY, required=False)

    class Meta:
        fields = (
                'priority', 'topic', 'subtopic', 'paper',
                )
        layout = (
                Fieldset('', 'priority', 'topic', 'subtopic', 'paper',),
                )

    def __init__(self, *args, **kwargs):
        event = kwargs.pop('event')
        #paper_topic = kwargs.pop('paper_topic')
        paper = kwargs.pop('paper')
        super(TopicForm, self).__init__(*args, **kwargs)
        self.fields['paper'].initial = paper.id
        self.fields['topic'].queryset = Topic.objects.\
                filter(setting=event.setting)
        self.fields['priority'].help_text = 'Primary - 1st Choice. Secondary - 2nd Choice.'
        #if paper_topic:
            #self.fields['topic'].initial = Topic.objects.\
                    #get(pk=paper_topic.topic.id)

    def clean(self):
        '''
        Limit topic associations to 2
        '''
        print 111, self.cleaned_data  # subtopic field is missing here
        cleaned_data = self.cleaned_data
        topic = cleaned_data.get('topic', None)
        subtopic = cleaned_data.get('subtopic', None)
        paper = cleaned_data.get('paper', None)
        priority = cleaned_data.get('priority', None)
        paper_obj = get_object_or_404(SubmissionImportData, pk=paper)

        if topic:
            topic_count = PaperTopic.objects.\
                    filter(submission_import_data=paper_obj).count()
            if topic_count >= 2:
                raise forms.ValidationError("You can only select up to two sets of topic and subtopic associations.")

        if PaperTopic.objects.filter(submission_import_data=paper_obj,
               priority=priority).exists():
            raise forms.ValidationError("You have already chosen that priority level.")
        if PaperTopic.objects.filter(submission_import_data=paper_obj,
               topic=topic, sub_topic=subtopic).exists():
            raise forms.ValidationError("You have already chosen that set of Topic and Subtopic association.")
        print 999999000000
        return cleaned_data

When I’m trying to submit my form, I’m getting this error:
<span class="help-inline">Select a valid choice. 29 is not one of the available choices.</span>.

I am generating the options for the subtopic dropdown list dynamically via AJAX based on the chosen value in topic.

I am able to get see subtopic in my request.POST but when it gets to the clean method, the subtopic field disappears.

I’m not too sure what’s going on..

UPDATE

Another thing, when there are no values for subtopic, the select element is set to disabled=disabled. When I try to submit my form like this, I am able to get subtopic field in my clean method. Whereas when the field is not disabled, I am not able to get it in my clean method. That’s like the opposite behaviour of what I’m expecting..

  • 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-03T03:43:31+00:00Added an answer on June 3, 2026 at 3:43 am

    ChoiceField() needs a list of choices to validate against to. Although you do
    this for topic

    self.fields['topic'].queryset = Topic.objects.\
                    filter(setting=event.setting)
    

    subtopic is initialized as an empty list, thus no option will be valid.

    You’ll have to initialize the self.fields['subtopic'].choices with every possible subtopic instance and decide with Javascript which subtopics will be shown/hidden(depending on which topic is selected).

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

Sidebar

Related Questions

HTML <form id=contact_form action=# name= method=POST> <label for=name>NAME</label> <input type=text name=name id=name class=contact_form_input />
I have an HTML form: <form action='process.php' method='post'> <input type='checkbox' name='check_box_1' /> Check me!<br>
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
A simple HTML form: <form enctype=application/x-www-form-urlencoded method=post action=/view/album/id/4><ol> <li class=no-padding><div class=element> <input type=hidden name=media
<form action=/Villa/Add method=post> <table> <tr> <td> Name: </td> <td> <%= Html.TextBox(name) %> <%= Html.ValidationMessage(Name)
I have a form with the following HTML below: <form id=course_edit_form name=course_form action=/courses/save method=post>
I am working on select box and using jquery. HTML structure: <form method= action=
I have a post html form, and the action is index.php, which is the
Here is the form: <%= form_tag({:controller => home, :action => tellafriend}, :method => post,
I'm trying to append a form to a div tag $('#courses_ajax').html('<h1>Materie: <%= @course.name %></h1>');

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.