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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:55:42+00:00 2026-05-19T06:55:42+00:00

What is the correct method for validating input for a custom multiwidget in each

  • 0

What is the correct method for validating input for a custom multiwidget in each of these cases:

  1. if I want to implement a custom Field?
  2. if I want to use an existing database field type (say DateField)?

The motivation for this comes from the following two questions:

  1. How do I use django’s multi-widget?
  2. Django subclassing multiwidget

I am specifically interested in the fact that I feel I have cheated. I have used value_from_datadict() like so:

def value_from_datadict(self, data, files, name):

    datelist = [widget.value_from_datadict(data, files, name + '_%s' % i) for i, widget in enumerate(self.widgets)]
    try:   
        D = date(day=int(datelist[0]), month=int(datelist[1]), year=int(datelist[2]))
        return str(D)
    except ValueError:
        return None

Which looks through the POST dictionary and constructs a value for my widget (see linked questions). However, at the same time I’ve tacked on some validation; namely if the creation of D as a date object fails, I’m returning None which will fail in the is_valid() check.

My third question therefore is should I be doing this some other way? For this case, I do not want a custom field.

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-19T06:55:44+00:00Added an answer on May 19, 2026 at 6:55 am

    You validate your form fields just like any other fields, implementing the clean_fieldname method in your form. If your validation logic spreads across many form fields (which is nto the same as many widgets!) you put it in your form’s clean() method.

    http://docs.djangoproject.com/en/1.2/ref/forms/validation/

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

Sidebar

Related Questions

I've got problems with setting focus to an input field after validating it. I've
What's the correct method for defining multi-line comments in an emacs mode (like C's
Am I correct to understand that the abort() method for XMLHttpRequest objects is only
In a Swing app a method should continue only after user enters a correct
I'm trying to write a custom method to validate a date. The date however
Correct me if I'm wrong, but a build is a compile, and not every
Correct me if I am wrong, int is 4 bytes, with a range of
Am I correct in assuming that the only difference between "windows files" and "unix
What is the correct way to import a C++ class from a DLL? We're
Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific

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.