torchbox/wagtail — pull request #656 by mope (2014-09-27 14:10:43+00:00)
Title: Fix 584

*Issue*

If a form is configured to have a checkbox field with multiple choices and a user submits that form with multiple boxes checked for that field, then only the last box checked will be recorded. This occurs because form data is extracted using the items() method.

*Fix*

I considered the following approaches:

1. When saving a form submission, convert lists to strings. Save all data as strings.
2. When saving a form submission, save all values as lists. Single values are saved as lists of one item. When form data is viewed in Wagtail Admin, display the lists as comma-separated strings.
3. When saving a form submission, save strings as strings and lists as lists.

This pull request implements option (2) for the following reasons:

1. Saving lists as lists preserves their structure. Saving all items as lists preserves uniformity of data representation.
2. The Wagtail Admin Forms page is likely to be viewed less often than the form itself and by administrators rather than website visitors, so it is better to incur performance overhead there.
3. This approach is much simpler than an implementation of option 3 would be.

Disadvantages of this approach:

1. Most field types do not require their values to be stored as lists, almost all saved forms submissions will consist of large numbers of single-entry lists.
2. Existing installations will have saved their form data as strings, but will begin saving it as lists after they upgrade. This will make reporting more complex and may break existing reporting code.