Display a warning if there are errors on the form
authorSverre Rabbelier <srabbelier@gmail.com>
Thu, 12 Mar 2009 23:05:40 +0000
changeset 1820 ecc40aa58e19
parent 1819 1e34fa8c5da0
child 1821 6a548cbb0f7e
Display a warning if there are errors on the form Patch by: Sverre Rabbelier
app/soc/templates/soc/templatetags/_as_table.html
app/soc/views/helper/templatetags/forms_helpers.py
--- a/app/soc/templates/soc/templatetags/_as_table.html	Thu Mar 12 23:04:53 2009 +0000
+++ b/app/soc/templates/soc/templatetags/_as_table.html	Thu Mar 12 23:05:40 2009 +0000
@@ -13,6 +13,13 @@
 {% endcomment %}
 {% load forms_helpers %}
 
+{% if errors %}
+<span class="formfielderrorlabel">
+There are errors on this form, please scroll down to see them. <br />
+Your changes have <i>not</i> been saved.
+</span>
+{% endif %}
+
 {% if hidden_field_errors or top_errors %}
 <ul class="errorlist">
 {% for field, error in hidden_field_errors %}
--- a/app/soc/views/helper/templatetags/forms_helpers.py	Thu Mar 12 23:04:53 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py	Thu Mar 12 23:05:40 2009 +0000
@@ -198,6 +198,7 @@
   fields = []
   hidden_fields = []
   hidden_fields_errors = []
+  errors = False
   
   # entity = context['entity']
 
@@ -214,6 +215,9 @@
 
     # If the field is hidden we display it elsewhere
     if not bf.is_hidden:
+      if bf.errors:
+        errors = True
+
       example_text = ''
       group = '0. '
 
@@ -246,6 +250,7 @@
   context.update({
       'top_errors': form.non_field_errors() or '',
       'hidden_field_errors': hidden_fields_errors or '',
+      'errors': errors,
       'groups': fields if fields else '',
       'hidden_fields': hidden_fields or '',
       })