From ab11a5f7ed5a25451e33d18ff06d7afc94a8d1b9 Mon Sep 17 00:00:00 2001 From: Arjun Singh Date: Wed, 18 Jul 2012 23:41:44 -0400 Subject: [PATCH] Allowing for form fields to submit more than one value; e.g. checkbox inputs. --- common/lib/xmodule/xmodule/capa_module.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 802a7c4895..5c166be19b 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -371,7 +371,16 @@ class CapaModule(XModule): for key in get: # e.g. input_resistor_1 ==> resistor_1 _, _, name = key.partition('_') - answers[name] = get[key] + + # This allows for answers which require more than one value for + # the same form input (e.g. checkbox inputs). The convention is that + # if the name ends with '[]' (which looks like an array), then the + # answer will be an array. + if not name.endswith('[]'): + answers[name] = get[key] + else: + name = name[:-2] + answers[name] = get.getlist(key) return answers