From 4add4e4272a05a8c9773f8a450d1f15b4fdf4b63 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 13 Dec 2006 06:26:04 +0000 Subject: Fixed #3114 -- newforms MultipleChoiceField now handles MultiValueDicts properly. Thanks for the patch, Honza Král MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@4196 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 825b44862d..7752060287 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1672,6 +1672,23 @@ MultipleChoiceField can also be used with the CheckboxSelectMultiple widget.
  • +Data for a MultipleChoiceField should be a list. QueryDict and MultiValueDict +conveniently work with this. +>>> data = {'name': 'Yesterday', 'composers': ['J', 'P']} +>>> f = SongForm(data) +>>> f.errors +{} +>>> from django.http import QueryDict +>>> data = QueryDict('name=Yesterday&composers=J&composers=P') +>>> f = SongForm(data) +>>> f.errors +{} +>>> from django.utils.datastructures import MultiValueDict +>>> data = MultiValueDict(dict(name='Yesterday', composers=['J', 'P'])) +>>> f = SongForm(data) +>>> f.errors +{} + When using CheckboxSelectMultiple, the framework expects a list of input and returns a list of input. >>> f = SongForm({'name': 'Yesterday'}, auto_id=False) -- cgit v1.3