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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:13:50+00:00 2026-05-21T20:13:50+00:00

I have a django form that I’m outputing no problem. My question is with

  • 0

I have a django form that I’m outputing no problem.

My question is with regard to jQuery Validation.
I want to apply jQuery validation to inputs that are required.
I’m using http://docs.jquery.com/Plugins/validation

There’s no field.is_required that I can use in the template
so I’m using the help_text and evaluating that in my template.

Just wondering if this is the best way to go about this?

Any advise much appreciated.

Here is:

1) Form Class

class UserDetailsForm(forms.Form):

    city_town = forms.CharField(label='City / Town',max_length=100, required=True, help_text='*')
    state_province = forms.CharField(label='State / Province',max_length=100, required=True, help_text='*')

2) Form output

{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field.help_text }} {{ field }}
</div>
{% endfor %}

3) Form jQuery Validation

// Form Validation Setup
{% for field in form %}
{% if field.help_text == '*' %}
$("input[name='{{ field.html_name }}']").addClass('required');
{% endif %}
{% endfor %}
$("#updateProfileForm").validate();

Is there any better method than the this work around I’m using:

if field.help_text == '*'

I may want to use that field for a tool tip of something later
but for now I’m using an asterisk so I can use it in a loop for jQuery validation
in the template.

Thanks!

  • 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-21T20:13:50+00:00Added an answer on May 21, 2026 at 8:13 pm

    When you iterate through a form instance, the __iter__ method returns a BoundField (that handles the rendering and other misc items). This bound field has a field attribute that stores the actual field instance (which does store the required attribute). So you can do

    {% if field.field.required %}
        $("input[name='{{ field.html_name }}']").addClass('required');
    {% endif %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Django form: class CommentForm(forms.Form): comment = forms.CharField(max_length=2000, required=True) post_id =
I'm trying to create a login and logout page with django. The problem I
I have this models in Django class Country(models.Model): name = models.CharField(max_length=80) class Person(models.Model): first_name
I have django models with a manytomany connection with a through class: class userProfile(models.Model):
I'm using django 1.3 I'm using a base.html template which my pages inherit from.
The officual django doc suggest to write the following in the settings.py ugettext =
I am creating a wiki in Django where users should be able to register,
Using Google motion chart for generating graph in django. i came accross with date
Hay, say i have 2 models listing and category. How would i use djangos
[Preamble: Whereas I realize there may be simpler ways to do this (i.e., just

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.