Added optional custom "status" argument to Form.add_error() method
authorThierry Florac <tflorac@ulthar.net>
Fri, 04 Oct 2019 12:54:42 +0200
changeset 195 e4b68da720e2
parent 194 d3ac1e9ec1c2
child 196 893cf2088818
Added optional custom "status" argument to Form.add_error() method
src/pyams_form/form.py
src/pyams_form/interfaces/form.py
--- a/src/pyams_form/form.py	Fri Oct 04 12:53:19 2019 +0200
+++ b/src/pyams_form/form.py	Fri Oct 04 12:54:42 2019 +0200
@@ -196,7 +196,7 @@
             result.extend(form.widgets.errors)
         return result
 
-    def add_error(self, error, widget):
+    def add_error(self, error, widget, status=None):
         if isinstance(error, str):
             error = Invalid(error)
         if isinstance(widget, str):
@@ -209,7 +209,7 @@
         self.widgets.errors += (snippet,)
         translate = self.request.localizer.translate
         if not self.status:
-            self.status = translate(self.formErrorsMessage)
+            self.status = translate(status or self.formErrorsMessage)
         self.status += '\n{0}'.format(translate(error.args[0]))
 
     def update_content(self, content, data):
--- a/src/pyams_form/interfaces/form.py	Fri Oct 04 12:53:19 2019 +0200
+++ b/src/pyams_form/interfaces/form.py	Fri Oct 04 12:54:42 2019 +0200
@@ -130,11 +130,12 @@
 
     is_dialog = Attribute("Check to know if current form is in a modal dialog")
 
-    def add_error(self, error, widget):
+    def add_error(self, error, widget, status=None):
         """Add error to current form status
 
         :param error: error can be defined as a simple string or as an error instance.
         :param widget: widget can be a widget name or a Widget instance.
+        :param status: if specified, allows to define a custom form status.
         """
 
     def get_form_action(self):