Opened 14 years ago

Closed 11 years ago

Last modified 11 years ago

#15511 closed New feature (fixed)

MultiValueField should allow subfield requirement

Reported by: Jeremy Dunck Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: timograham@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Example:

class PhoneFIeld(MultiValueField):
    def __init__(self, **kwargs):
        super(PhoneField).__init__(self, fields=(
            USPhoneNumberField(required=True),
            forms.CharField(error_messages={'invalid': u'Extension must be numeric'},
                required=False),
        ), required=True)

This would require a change to .clean so that all subfields which were marked required to be filled in, but any non-required subfield would not be required.

Currently, subfield required's are forced to False, and a required at the MultiValueField level means all subfields are required.

Change History (12)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Łukasz Rekucki, 14 years ago

Severity: Normal
Type: New feature

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Tai Lee, 12 years ago

Has patch: set
Version: 1.2master

I have opened a PR with backwards compatible fix, tests and docs.

https://github.com/django/django/pull/1048

comment:6 by Tai Lee, 12 years ago

This also refs #13342 which was closed as wontfix by russellm who accepted this ticket. Presumably this ticket now includes sufficient detail.

comment:7 by Tim Graham, 11 years ago

Cc: timograham@… added
Patch needs improvement: set

PR needs to be rebased to master.

comment:8 by Tai Lee, 11 years ago

Patch needs improvement: unset

Rebased to master.

comment:9 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 12806758347dfd63a3cd1bfc0d925c09fdbd9cff:

Fixed #15511 -- Allow optional fields on MultiValueField` subclasses.

The MultiValueField class gets a new require_all_fields argument that
defaults to True. If set to False, individual fields can be made
optional, and a new incomplete validation error will be raised if any
required fields have empty values.

The incomplete error message can be defined on a MultiValueField
subclass or on each individual field. Skip duplicate errors.

comment:10 by Nathan Osman, 11 years ago

Just a quick clarification: will this fix make it into the final Django 1.6 release?

comment:11 by Tim Graham, 11 years ago

No, if you look at the commit you'll see it's been added to the release notes for 1.7.

comment:12 by Nathan Osman, 11 years ago

After a significant amount of effort, I have succeeded in backporting this fix to Django 1.5.2. Unfortunately, it wasn't possible to backport this fix (#15511) without also backporting #17051. So, here is a patch that combines the fix for both bugs:

https://gist.github.com/nathan-osman/6347178

I ran the test suite after applying the patch and it seemed to pass without any failures.

Note: See TracTickets for help on using tickets.
Back to Top