--- a/src/pyams_form/form.py Sun Mar 11 11:23:25 2018 +0100
+++ b/src/pyams_form/form.py Tue Mar 13 16:33:29 2018 +0100
@@ -358,13 +358,24 @@
except ValidationError as error:
# This error can occur with file-type inputs
registry = self.request.registry
- widget = self.widgets[error.args[-1]]
- view = registry.getMultiAdapter((error, self.request, widget, widget.field, self, self.context),
- IErrorViewSnippet)
- view.update()
- widget.error = view
- errors = (view,)
- return self.get_ajax_errors(errors)
+ for form in self.forms:
+ try:
+ widget = form.widgets[error.args[-1]]
+ except KeyError:
+ continue
+ else:
+ view = registry.getMultiAdapter((error, self.request, widget, widget.field, self, self.context),
+ IErrorViewSnippet)
+ view.update()
+ widget.error = view
+ errors = (view,)
+ return self.get_ajax_errors(errors)
+ # Fallback when you can't find widget
+ translate = self.request.localizer.translate
+ return {
+ 'status': 'error',
+ 'message': translate(self.formErrorsMessage)
+ }
else:
return self.get_ajax_output(result)
@@ -459,22 +470,32 @@
if errors or self.errors:
return self.get_ajax_errors()
# update form content
+ translate = self.request.localizer.translate
try:
changes = self.applyChanges(data) or {}
except ValidationError as error:
# This error can occur with file-type inputs
registry = self.request.registry
- widget = form.widgets[error.args[-1]]
- view = registry.getMultiAdapter((error, self.request, widget, widget.field, self, self.context),
- IErrorViewSnippet)
- view.update()
- widget.error = view
- errors = (view,)
- return self.get_ajax_errors(errors)
+ for form in self.forms:
+ try:
+ widget = form.widgets[error.args[-1]]
+ except KeyError:
+ continue
+ else:
+ view = registry.getMultiAdapter((error, self.request, widget, widget.field, self, self.context),
+ IErrorViewSnippet)
+ view.update()
+ widget.error = view
+ errors = (view,)
+ return self.get_ajax_errors(errors)
+ # Fallback when you can't find widget
+ return {
+ 'status': 'error',
+ 'message': translate(self.formErrorsMessage)
+ }
else:
# check JSON output
output = self.get_ajax_output(changes)
- translate = self.request.localizer.translate
status = output.get('status')
message = output.get('message')
if not changes: