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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:55:20+00:00 2026-06-08T06:55:20+00:00

I am using django and dajax and I am trying to validate an item

  • 0

I am using django and dajax and I am trying to validate an item that has a many-to-many field. I am using the django forms to create the form for this model. When I submit the form with a submit button and have at least 1 to x number of items selected in the selectbox, the model gets validated. When I use dajax, the model will only validate if I have atleast 2 of the items in the select box are selected.

Does anyone know why this would happen?

Model

#Hints
class Hint(models.Model):
title = models.TextField(max_length=200)
body = models.TextField()
industryType = models.ManyToManyField(IndustryType)
screen = models.ManyToManyField(Screen)

#Creates form for a hint
class HintForm(ModelForm):

class Meta:
    model = Hint
    #widgets = {'industryType': CheckboxSelectMultiple, 'screen': CheckboxSelectMultiple }
    industryType = ModelMultipleChoiceField(queryset=IndustryType.objects.all(),
                                                widget=CheckboxSelectMultiple())

Template:

<form id="hintForm"  action="." method="post">

{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit"/>
</form>

<input type="button"  onclick="send_form();" value="Add Hint" />

<script>
function send_form(){
    data = $('#hintForm').serializeObject();

    // jQuery
    // If you are using jQuery, you need this form->object serializer
    // https://github.com/cowboy/jquery-misc/blob/master/jquery.ba-serializeobject.js
        alert(data['screen'])
        Dajaxice.THE.send_form(Dajax.process,{'hintform':data});
        return(false)
}

</script>

Code in the View

def addHint(request):
if request.method == 'POST': # If the form has been submitted...
    form = HintForm(request.POST) # A form bound to the POST data
    if form.is_valid(): # All validation rules pass
        # Process the data in form.cleaned_data
        #savedHint = form.save()
        #messages.success(request, '{0} has been added.'.format(savedHint))
        print "Success"
else:

    form = HintForm() # An unbound form

return render_to_response('manage/screens/form.html', {
    'form': form, 'breadcrumName' : 'Add Screen' }, context_instance=RequestContext(request))

AJAX.py

@dajaxice_register
def send_form(request, hintform):
    dajax = Dajax()
    form = HintForm(hintform)
    print form
    if form.is_valid():

        dajax.alert("This form is_valid")
    else:

        dajax.alert("Not Valid")
    return dajax.json()
  • 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-08T06:55:21+00:00Added an answer on June 8, 2026 at 6:55 am

    I had problems serializing form data using Dajax until I switched to a different serialize object function. I realize this isn’t a comprehensive and tested answer to your question but you could give this alternate serialize function a shot:

    https://github.com/danheberden/serializeObject

    Maybe also do some firebug / console output for your serialized form object to see if/how it’s being munged.

    Cheers

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

Sidebar

Related Questions

Am using django forms on my app. I have a model Client like this:
I'm using django/apache/sqlite3 and I have a django model that looks like this: class
I am using Django Crispy Forms together with Twitter-bootstrap and following this page: http://django-crispy-forms.readthedocs.org/en/d-0/tags.html#bootstrap-layout-objects
Well, I have one form, similar to dajax django forms example, all is working
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
I am working on form validation with AJAX using Dajax in a Django project.
Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from
Using Django 1.1, I am trying to select the maximum value from a varchar
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I using Django tagging project. That is was very stable project. Working on django

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.