Added custom form error message
authorThierry Florac <tflorac@ulthar.net>
Fri, 04 Oct 2019 13:40:05 +0200
changeset 469 b8d287df9d34
parent 468 68685437bb93
child 470 3219fd0a7366
Added custom form error message
src/pyams_default_theme/shared/form/__init__.py
--- a/src/pyams_default_theme/shared/form/__init__.py	Thu Sep 26 11:58:24 2019 +0200
+++ b/src/pyams_default_theme/shared/form/__init__.py	Fri Oct 04 13:40:05 2019 +0200
@@ -48,6 +48,7 @@
 RECAPTCHA_FIELD_NAME = 'g-recaptcha-response'
 RGPD_CONSENT_FIELD_NAME = 'rgpd_consent'
 
+FORM_SUBMIT_ERROR_STATUS = _("Can't submit form.")
 MISSING_TOKEN_ERROR = _("Missing recaptcha token!")
 INVALID_TOKEN_ERROR = _("Can't verify recaptcha token! Are you a robot?")
 
@@ -63,6 +64,8 @@
 class FormFieldContainerInputForm(AddForm):
     """Form fields container display form"""
 
+    formErrorsMessage = FORM_SUBMIT_ERROR_STATUS
+
     @property
     def legend(self):
         return II18n(self.context).query_attribute('user_title', request=self.request)
@@ -169,11 +172,12 @@
                     del data[RECAPTCHA_FIELD_NAME]
                 # convert form data
                 user_data = data.copy()
-                for field in IFormFieldContainer(form).get_fields():
-                    converter = request.registry.queryMultiAdapter((field, request),
+                for form_field in IFormFieldContainer(form).get_fields():
+                    converter = request.registry.queryMultiAdapter((form_field, request),
                                                                    IFormFieldDataConverter)
                     if converter is not None:
-                        user_data[field.__name__] = converter.convert(data.get(field.__name__))
+                        user_data[form_field.__name__] = converter.convert(
+                            data.get(form_field.__name__))
                 output = handler.handle(form, data, user_data)
                 if output:
                     request.annotations['form.output'] = output