flask-bootstrap icon indicating copy to clipboard operation
flask-bootstrap copied to clipboard

checkbox on form_field does not display error message

Open outofsyncme opened this issue 9 years ago • 1 comments

I might be missing something here, but it looks like field.errors is not checked in form_field macro for checkbox type and the error message is not being displayed.

I was following the example at http://flask.pocoo.org/docs/0.10/patterns/wtforms/ for BooleanField with Required validation.

class ExampleForm(Form):
    ...
    checkbox_field = BooleanField('This is a checkbox',
                                  description='Checkboxes can be tricky.',
                                  validators=[Required()])

My quick fix still need some work:

{% if field.widget.input_type == 'checkbox' %}
  {% call _hz_form_wrap(horizontal_columns, form_type, True, required=required) %}

    {% if field.errors %}<div class="has-warning">{% endif %}

        <div class="checkbox">
          <label>
            {{field()|safe}} {{field.label.text|safe}}
          </label>
        </div>

        {%- if field.errors %}
          {%- for error in field.errors %}
                <p class="help-block">{{error}}</p>
          {%- endfor %}
        {% endif %}

    {% if field.errors %}</div><!-- /has-warning-->{% endif %}

  {% endcall %}

outofsyncme avatar Apr 05 '15 18:04 outofsyncme

this works fine for me. thanks @outofsyncme. In my case I replace has-warning with has-error

ar-anvd avatar Jul 14 '16 11:07 ar-anvd