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 select2 widgets rendering empty values in display mode when called from an easyform action #6

Open
wants to merge 1 commit into
base: mtneers
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/collective/easyform/browser/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,23 @@ def setErrorsMessage(self, errors):
self.widgets[field].error = view
self.status = self.formErrorsMessage

def fix_select2_widgets(self):
# Plone Select widgets store values as strings, but
# the display widget expects the extracted list,
# so we need to fix the request form data here
# before actions are triggered.
for name, widget in self.widgets.items():
is_select = ISelectWidget.providedBy(widget)
if is_select:
request_value = self.request.form.get("form.widgets.{}".format(name))
if request_value and isinstance(request_value, six.string_types):
self.request.form["form.widgets.{}".format(name)] = (request_value,)

@button.buttonAndHandler(
PMF(u"Submit"), name="submit", condition=lambda form: not form.thanksPage
)
def handleSubmit(self, action):
self.fix_select2_widgets()
unsorted_data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
Expand Down Expand Up @@ -402,7 +415,6 @@ def form_name(self):
if self.context.nameAttribute:
return self.context.nameAttribute
return None


def getOnDisplayOverride(self):
"""Evaluate form setup script TALES expression stored in the
Expand Down
Loading