Get back-and-forth of form validation working
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
{% from "second/macros.html" import with_errors %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -9,10 +11,8 @@
|
||||
<p>Install {{ app_name }}</p>
|
||||
<form method="POST" action="/deploy/{{ app_name }}">
|
||||
{% for field in form %}
|
||||
<div>
|
||||
{{ field.label() }}
|
||||
{{ field() }}
|
||||
</div>
|
||||
{{ with_errors(field, style='font-weight: bold') }}
|
||||
{% endfor %}
|
||||
<input type="submit" value="Deploy" />
|
||||
</form>
|
||||
|
16
templates/second/macros.html
Normal file
16
templates/second/macros.html
Normal file
@ -0,0 +1,16 @@
|
||||
{#
|
||||
From: https://wtforms.readthedocs.io/en/2.3.x/specific_problems/#rendering-errors
|
||||
Usage: with_errors(form.field, style='font-weight: bold')
|
||||
#}
|
||||
|
||||
{% macro with_errors(field) %}
|
||||
<div class="form_field">
|
||||
{% if field.errors %}
|
||||
{% set css_class = 'has_error ' + kwargs.pop('class', '') %}
|
||||
{{ field(class=css_class, **kwargs) }}
|
||||
<ul class="errors">{% for error in field.errors %}<li>{{ error|e }}</li>{% endfor %}</ul>
|
||||
{% else %}
|
||||
{{ field(**kwargs) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
Reference in New Issue
Block a user