Permalink
Browse files

add twitter bootstraps error messages to forms

  • Loading branch information...
1 parent 608f765 commit feac08b979dbba43f64564be66e920700726c05f @reecefowell reecefowell committed Jul 1, 2012
@@ -29,25 +29,27 @@
<form action="{{ path('cc_admin_forum_board_create') }}" method="post" {{ form_enctype(form) }} class="form-horizontal">
<fieldset>
+ {{ form_errors(form) }}
+
<div class="control-group"><div class="controls row-fluid">{{ form_row(form._token) }}</div></div>
- <div class="control-group">
+ <div class="control-group{{ (form.category.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.category, null, { 'label': 'form.label.board.category'| trans({}, 'CCDNForumAdminBundle') }) }}
<div class="controls row-fluid">
{{ form_errors(form.category) }}
{{ form_widget(form.category) }}
</div>
</div>
-
- <div class="control-group">
+
+ <div class="control-group{{ (form.name.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.name, null, { 'label': 'form.label.board.name'| trans({}, 'CCDNForumAdminBundle')}) }}
<div class="controls row-fluid">
{{ form_errors(form.name) }}
{{ form_widget(form.name) }}
</div>
</div>
-
- <div class="control-group">
+
+ <div class="control-group{{ (form.description.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.description, null, { 'label': 'form.label.board.description'| trans({}, 'CCDNForumAdminBundle')}) }}
<div class="controls row-fluid">
{{ form_errors(form.description) }}
@@ -28,25 +28,28 @@
<form action="{{ path('cc_admin_forum_board_edit', {'board_id': board.id}) }}" method="post" {{ form_enctype(form) }} class="form-horizontal">
<fieldset>
+
+ {{ form_errors(form) }}
+
<div class="control-group"><div class="controls row-fluid">{{ form_row(form._token) }}</div></div>
- <div class="control-group">
+ <div class="control-group{{ (form.category.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.category, null, { 'label': 'form.label.board.category'| trans({}, 'CCDNForumAdminBundle') }) }}
<div class="controls row-fluid">
{{ form_errors(form.category) }}
{{ form_widget(form.category) }}
</div>
</div>
- <div class="control-group">
+ <div class="control-group{{ (form.name.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.name, null, { 'label': 'form.label.board.name'| trans({}, 'CCDNForumAdminBundle') }) }}
<div class="controls row-fluid">
{{ form_errors(form.name) }}
{{ form_widget(form.name) }}
</div>
</div>
- <div class="control-group">
+ <div class="control-group{{ (form.description.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.description, null, { 'label': 'form.label.board.description'| trans({}, 'CCDNForumAdminBundle') }) }}
<div class="controls row-fluid">
{{ form_errors(form.description) }}
@@ -30,9 +30,11 @@
<form action="{{ path('cc_admin_forum_category_create') }}" method="post" {{ form_enctype(form) }} class="form-horizontal">
<fieldset>
+ {{ form_errors(form) }}
+
<div class="control-group"><div class="controls row-fluid">{{ form_row(form._token) }}</div></div>
- <div class="control-group">
+ <div class="control-group{{ (form.name.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.name, null, { 'label': 'form.label.category.name' | trans({}, 'CCDNForumAdminBundle') }) }}
<div class="controls row-fluid">
{{ form_errors(form.name) }}
@@ -30,9 +30,11 @@
<form action="{{ path('cc_admin_forum_category_edit', {'category_id': category.id}) }}" method="post" {{ form_enctype(form) }} class="form-horizontal">
<fieldset>
+ {{ form_errors(form) }}
+
<div class="control-group"><div class="controls row-fluid">{{ form_row(form._token) }}</div></div>
- <div class="control-group">
+ <div class="control-group{{ (form.name.vars.errors|length > 0) ? ' error': '' }}">
{{ form_label(form.name, null, { 'label': 'form.label.category.name'| trans({}, 'CCDNForumAdminBundle') }) }}
<div class="controls row-fluid">
{{ form_errors(form.name) }}
@@ -1,7 +1,9 @@
{% block field_label %}
{% spaceless %}
{% set attr = attr|merge({ 'class': attr.class|default('') ~ 'control-label'}) %}
- <label for="{{ id }}" {{ block('widget_attributes') }}>{{ label }}</label>
+ <label for="{{ id }}" {{ block('widget_attributes') }}>{{- label -}}{%- if required -%}
+ <span style="color:#f00;" title="{{ 'form.field.required' |trans({}, 'CCDNUserUserBundle') }}">*</span>
+ {%- endif -%}</label>
{% endspaceless %}
{% endblock field_label %}
@@ -17,4 +19,32 @@
{% block textarea_widget %}
{% set attr = attr|merge({ 'class': attr.class|default('') ~ 'text-xlarge span8', 'style': attr.style|default('') ~ 'height:250px;'}) %}
<textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
-{% endblock textarea_widget %}
+{% endblock textarea_widget %}
+
+{% block field_errors %}{# errors for next to each field #}
+{%- spaceless -%}
+ {% if errors|length > 0 %}
+ <div class="alert alert-error span8">
+ <ul>
+ {% for error in errors %}
+ <li>{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</li>
+ {% endfor %}
+ </ul>
+ </div>
+ {%- endif -%}
+{% endspaceless %}
+{% endblock field_errors %}
+
+{% block form_errors %}{# for the overall form #}
+{%- spaceless -%}
+ {% if errors|length > 0 %}
+ <div class="alert alert-error span8">
+ <ul>
+ {% for error in errors %}
+ <li>{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</li>
+ {% endfor %}
+ </ul>
+ </div>
+ {%- endif -%}
+{% endspaceless %}
+{% endblock form_errors %}

0 comments on commit feac08b

Please sign in to comment.