Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added in better support for uni-form errorMsg

  • Loading branch information...
commit 51f4e8c71cb85014f3fad6f5efcdb1b428762fe8 1 parent bfb3afc
@pydanny pydanny authored
View
50 test_project/test_app/forms.py
@@ -73,50 +73,12 @@ class LayoutTestForm(forms.Form):
submit = Submit('add','Add this contact')
helper.add_input(submit)
-
+class MessageResponseForm(forms.Form):
-class ComplexLayoutTest(forms.Form):
- """
- TODO: get digi604 to make this work
+ character_field = forms.CharField(label="Character Field", help_text="I am help text", max_length=30, required=True, widget=forms.TextInput())
- help_text = render_to_string("example/help_text.html")
- layout = Layout(Fieldset(_('Basic Settings'),
- 'title',
- 'type',
- 'available_date',
- ),
- Fieldset(_('Overview'),
- Column(Fieldset(_('Object address'),
- Row('address', 'street_number'),
- Row('zip', 'city'),
- 'area',
- ),
- Fieldset(_("Next public transport"),
- 'train_station',
- Row('tram_station','tram_number'),
- Row('bus_station','bus_number'),
- ),
- ),
- Column("is_for_rent",
- Fieldset(_("Rent"),
- 'rent-price',
- ),
- Fieldset(_("Sell"),
- 'buy_price',
- ),
- Fieldset(_("Measurements"),
- 'floor_space',
- 'room_height',
- 'construction_year',
- ),
- ),
- Fieldset(_('Additional Function'),
- HTML('<p class="tip">%s</p>' % unicode(help_text)),
- 'features',
- ),
- Fieldset(_("Description"),
- "description")
- )
- helper.add_layout(layout)
- """
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ raise forms.ValidationError("This is a forced error")
+ return cleaned_data
View
1  test_project/test_app/templates/test_app/base.html
@@ -122,6 +122,7 @@
<li><a href="{% url layout_test %}">Layout test</a></li>
<li><a href="{% url set_action_test %}">Set action test</a></li>
<li><a href="{% url lacking_form_tag %}">Lacking form tag</a></li>
+ <li><a href="{% url message_response %}">Message Response</a></li>
</ul>
</div>
View
11 test_project/test_app/templates/test_app/message_response.html
@@ -0,0 +1,11 @@
+{% extends "test_app/base.html" %}
+{% load uni_form_tags %}
+
+{% block body%}
+<h1>
+ Django Uni-Form message response test
+</h1>
+
+{% uni_form form helper %}
+
+{% endblock %}
View
1  test_project/test_app/urls.py
@@ -9,6 +9,7 @@
url(r'^layout_test/$', "test_app.views.layout_test", name='layout_test'),
url(r'^view_helper_set_action/$', "test_app.views.view_helper_set_action", name='set_action_test'),
url(r'^lacking_form_tag/$', "test_app.views.lacking_form_tag", name='lacking_form_tag'),
+ url(r'^message_response/$', "test_app.views.message_response", name='message_response'),
)
View
28 test_project/test_app/views.py
@@ -4,7 +4,7 @@
from uni_form.helpers import FormHelper, Submit, Reset, Hidden
-from test_app.forms import TestForm, HelperTestForm, LayoutTestForm
+from test_app.forms import TestForm, HelperTestForm, LayoutTestForm, MessageResponseForm
def basic_test(request):
if request.method == "POST":
@@ -107,4 +107,28 @@ def lacking_form_tag(request):
return render_to_response('test_app/lacking_form_tag.html',
response_dictionary,
context_instance=RequestContext(request))
-
+
+def message_response(request):
+
+ if request.method == "POST":
+ form = MessageResponseForm(request.POST)
+ else:
+ form = MessageResponseForm()
+
+ # create a formHelper
+ helper = FormHelper()
+
+ # add in a error and success button
+ error = Submit('generate-result','Generate Error')
+ helper.add_input(error)
+
+ # add in a submit and reset button
+ success = Submit('generate-result','Generate Success')
+ helper.add_input(success)
+
+ # create the response dictionary
+ response_dictionary = {'form':form, 'helper': helper}
+
+ return render_to_response('test_app/message_response.html',
+ response_dictionary,
+ context_instance=RequestContext(request))
View
15 uni_form/templates/uni_form/whole_uni_form.html
@@ -1,10 +1,21 @@
{% load uni_form_tags i18n %}
+
{% if form_tag %}<form action="{{ form_action|lower }}" class="uniForm{% if form_class %} {% endif %}{{ form_class }}" method="{{ form_method }}"{% if form_id %} id="{{ form_id|slugify }}"{% endif %}{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>{% endif %}
- {% if form_html %}{{ form_html }}{% else %}
+ {% if form.non_field_errors %}
+ <div id="errorMsg">
+ <h3>{% if error_message_title %}{{ error_message_title }}{% else %}Errors{% endif %}</h3>
+ <ol>
+ {{ form.non_field_errors|unordered_list }}
+ </ol>
+ </div>
+ {% endif %}
+ {% if form_html %}{{ form_html }}{% else %}
<fieldset class="inlineLabels">
<legend>* {% trans "Required fields" %}</legend>
- {{ form|as_uni_form }}
+ {% for field in form %}
+ {% include "uni_form/field.html" %}
+ {% endfor %}
</fieldset>
{% endif %}
{% if inputs %}
View
9 uni_form/templatetags/uni_form_tags.py
@@ -82,16 +82,19 @@ def get_render(self, context):
attrs = None
if helper:
if not isinstance(helper, FormHelper):
- raise TypeError('helper object provided to uni_form tag must be a uni_form.helpers.FormHelper object or a None object.')
+ raise TypeError('helper object provided to uni_form tag must be a uni_form.helpers.FormHelper object.')
attrs = helper.get_attr()
form_class = ''
form_id = ''
+ form_method = 'post'
+ form_action = ''
+ form_tag = True
inputs = []
toggle_fields = set(())
if attrs:
form_tag = attrs.get("form_tag", True)
- form_method = attrs.get("form_method", 'POST')
- form_action = attrs.get("form_action", '')
+ form_method = attrs.get("form_method", form_method)
+ form_action = attrs.get("form_action", form_action)
form_class = attrs.get("class", '')
form_id = attrs.get("id", "")
inputs = attrs.get('inputs', [])
Please sign in to comment.
Something went wrong with that request. Please try again.