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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:37:38+00:00 2026-06-04T02:37:38+00:00

I have a pretty big form, wich has two possibilities. It is a form

  • 0

I have a pretty big form, wich has two possibilities. It is a form for an event, and the event location can be picked from a combobox (ModelChoice query). However, there is the possibility for the user to check the “New location” checkbox, and then the form shows the fields neccessary to insert the new location as well, and the “existing locations” combobox is reset. Now, this all works very nice with javascript (jQuery), but my problem is how to validate the unused fields in the form.

To put it simple> I have i.e. 7 form fileds, 3 of them are always mandatory (event type, datetime etc), while the other depend on the state of the checkbox “new location”: if new_location is checked> validate the location etc fields, and ignore the rest (allow them to be empty), otherwisw ignore the location fields and validate the rest.

class EventForm(ModelForm):

    area = forms.ModelChoiceField(
        queryset=Area.objects.order_by('name').all(),
        empty_label=u"Please pick an area",
        label=u'Area',
        error_messages={'required':u'The area is mandatory!'})

    type = forms.ModelChoiceField(
        queryset=SportType.objects.all(),
        empty_label=None,
        error_messages={'required':'Please pick a sport type!'},
        label=u"Sport")

    #shown only if new_location is unchecked - jQuery
    location = forms.ModelChoiceField(
        queryset=Location.objects.order_by('area').all(),
        empty_label=u"Pick a location",
        error_messages={'required':'Please pick a location'},
        label=u'Location')

    #trigger jQuery - hide/show new location field
    new_location = forms.BooleanField(
        required=False,
        label = u'Insert new location?'
            )

    address = forms.CharField(
        label=u'Locatio address',
        widget=forms.TextInput(attrs={'size':'30'}),
        error_messages={'required': 'The address is required'})

    location_description = forms.CharField(
        label=u'Brief location description',
        widget=forms.Textarea(attrs={'size':'10'}),
        error_messages={'required': 'Location description is mandatory'})

    class Meta:
        model = Event
        fields = (
            'type',
            'new_location',
            'area',
            'location',
            'address',
            'location_description',
            'description',
        )
  • 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-04T02:37:40+00:00Added an answer on June 4, 2026 at 2:37 am

    I ended up using just a normal form (not ModelForm) and custom validation with clean(self) depending on the state of the checkbox, I think it is the right way to go. Then with self._errors["address"]=ErrorList([u'Some custom error']) I was able to fully customise the various errors that could come up during the validation process.

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

Sidebar

Related Questions

I have a pretty big data entry form which has many text fields ,
I have a pretty big form with over 4000 values defined by the <option>
I have a pretty big query to pull out the information about reports from
We have pretty big (~200mb) xml files from different sources that we want to
I have a pretty big view which is like 1000 x 1000. So I
I have a pretty big problem with my TabHost. Although I have declared all
I have been trying to serialize a pretty big object. This object uses dictionaries
I have a very strange situation. I´m working on a pretty big Java application
I have an image on a webpage. It's a pretty big image, however. It's
I'm here to get some information. We have a product thats pretty big and

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.