Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#15511 closed New feature (fixed)

MultiValueField should allow subfield requirement

Reported by: jdunck Owned by: nobody
Component: Forms Version: master
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



class PhoneFIeld(MultiValueField):
    def __init__(self, **kwargs):
        super(PhoneField).__init__(self, fields=(
            forms.CharField(error_messages={'invalid': u'Extension must be numeric'},
        ), 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 Changed 6 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 3 years ago by mrmachine

  • Has patch set
  • Version changed from 1.2 to master

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

comment:6 Changed 3 years ago by mrmachine

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

comment:7 Changed 3 years ago by timo

  • Cc timograham@… added
  • Patch needs improvement set

PR needs to be rebased to master.

comment:8 Changed 3 years ago by mrmachine

  • Patch needs improvement unset

Rebased to master.

comment:9 Changed 3 years ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

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 Changed 3 years ago by george_edison

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

comment:11 Changed 3 years ago by timo

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

comment:12 Changed 3 years ago by george_edison

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:

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