Skip to content

Commit

Permalink
Fix #396. Custom action scripts gets server side flagged fields in th…
Browse files Browse the repository at this point in the history
…e `fields` dict parameter under the `name_of_the_field` key.
  • Loading branch information
sauzher committed Jan 12, 2023
1 parent c33922c commit ad9c911
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/collective/easyform/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,20 @@ def getScript(self, context):
script.ZPythonScript_edit(params, body)
return script

def sanifyFields(self, form):
def sanifyFields(self, form, fields):
# Makes request.form fields accessible in a script
#
# Avoid Unauthorized exceptions since request.form is inaccesible

result = {}
for field in form:
result[field] = form[field]

# append in the results all serverside fields variable
for field in fields:
key = 'form.widgets.{}'.format(field)
if key not in result:
result[field] = fields[field]
return result

def checkWarningsAndErrors(self, script):
Expand Down Expand Up @@ -638,7 +644,7 @@ def executeCustomScript(self, result, form, req):
def onSuccess(self, fields, request):
# Executes the custom script
form = get_context(self)
resultData = self.sanifyFields(request.form)
resultData = self.sanifyFields(request.form, fields)
return self.executeCustomScript(resultData, form, request)


Expand Down

0 comments on commit ad9c911

Please sign in to comment.