From c0e01416b68e482172ef23cc507f163b873c192a Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 27 Jan 2007 21:41:32 +0000 Subject: [PATCH] Fixed #3312 -- CheckboxSelectMultiple no longer uses duplicate ID attributes for each checkbox git-svn-id: http://code.djangoproject.com/svn/django/trunk@4436 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/widgets.py | 9 +++++++-- tests/regressiontests/forms/tests.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py index 3c27f7e2c11..585e12cc181 100644 --- a/django/newforms/widgets.py +++ b/django/newforms/widgets.py @@ -258,11 +258,16 @@ class RadioSelect(Select): class CheckboxSelectMultiple(SelectMultiple): def render(self, name, value, attrs=None, choices=()): if value is None: value = [] + has_id = attrs and attrs.has_key('id') final_attrs = self.build_attrs(attrs, name=name) output = [u' +Regarding auto_id, CheckboxSelectMultiple is a special case. Each checkbox +gets a distinct ID, formed by appending an underscore plus the checkbox's +zero-based index. +>>> f = SongForm(auto_id='%s_id') +>>> print f['composers'] + + Data for a MultipleChoiceField should be a list. QueryDict and MultiValueDict conveniently work with this. >>> data = {'name': 'Yesterday', 'composers': ['J', 'P']}