Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #584 #768

Closed

Conversation

kaedroho
Copy link
Contributor

Continuation of #656

Original message by @mope

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:

  • When saving a form submission, convert lists to strings. Save all data as strings.
  • 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.
  • When saving a form submission, save strings as strings and lists as lists.

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

  • Saving lists as lists preserves their structure. Saving all items as lists preserves uniformity of data representation.
  • 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.
  • This approach is much simpler than an implementation of option 3 would be.

Disadvantages of this approach:

  • 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.
  • 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.

Tom Talbot and others added 4 commits October 30, 2014 09:45
This allows form submission fields with multiple values to be saved correctly.
Not available in Python 3. Using six.iteritems() instead
Was using assertTrue(x in y) which doesn't print out the text that was
being used in the assertion
@kaedroho kaedroho added this to the 0.8 milestone Oct 30, 2014
@kaedroho kaedroho self-assigned this Oct 30, 2014
@kaedroho kaedroho changed the title Fix #584 [WIP] Fix #584 Oct 30, 2014
@kaedroho kaedroho mentioned this pull request Oct 30, 2014
@kaedroho kaedroho assigned gasman and unassigned kaedroho Oct 30, 2014
@kaedroho kaedroho changed the title [WIP] Fix #584 Fix #584 Oct 30, 2014
Going to try a different approach
This fixes wagtail#584. It also doesn't pack single values into lists and will
remove csrftoken for us.
@kaedroho kaedroho force-pushed the mope-584-fix-formbuilder-checkboxes branch from 930b663 to c2cfdc6 Compare October 30, 2014 11:00
gasman added a commit that referenced this pull request Oct 30, 2014
@gasman
Copy link
Collaborator

gasman commented Oct 30, 2014

Merged in b14d8d3 (with a rebase to clean up the commit history).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants