HTML validation + Actually associate messages to errors + Fix inverted behavior on new blog and post form

This commit is contained in:
Bat
2018-07-07 22:51:48 +02:00
parent e5c1b3259d
commit 3775d3a9c9
10 changed files with 34 additions and 24 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
{% block content %}
<h1>{{ "Create a blog" | _ }}</h1>
<form method="post">
{{ macros::input(name="title", label="Title", errors=errors, form=form) }}
{{ macros::input(name="title", label="Title", errors=errors, form=form, props='required minlength="1"') }}
<input type="submit" value="{{ "Create blog" | _ }}"/>
</form>
+3 -3
View File
@@ -21,12 +21,12 @@
</p>
</div>
{% endmacro post_card %}
{% macro input(name, label, errors, form, type="text") %}
{% macro input(name, label, errors, form, type="text", props="") %}
<label for="{{ name }}">{{ label | _ }}</label>
{% if errors is defined and errors[name] %}
{% for err in errors[name] %}
<p class="error">{{ err.message | _ }}</p>
<p class="error">{{ err.message | default(value="Unknown error") }}</p>
{% endfor %}
{% endif %}
<input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value="") }}"/>
<input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value="") }}" {{ props | safe }}/>
{% endmacro input %}
+3 -3
View File
@@ -1,4 +1,5 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "New post" | _ }}
@@ -9,14 +10,13 @@
<form class="new-post" method="post">
{{ macros::input(name="title", label="Title", errors=errors, form=form) }}
<label for="{{ name }}">{{ label | _ }}</label>
{% if errors is defined and errors.content %}
{% for err in errors.content %}
<p class="error">{{ err.message | _ }}</p>
<p class="error">{{ err.message | default(value="Unknown error") | _ }}</p>
{% endfor %}
{% endif %}
<textarea name="content" placeholder="{{ "Content" | _ }}" value="{{ form.content | default(value="") }}"></textarea>
<textarea id="content" name="content" placeholder="{{ "Content" | _ }}" value="{{ form.content | default(value="") }}"></textarea>
{{ macros::input(name="license", label="License", errors=errors, form=form) }}
+3 -2
View File
@@ -1,4 +1,5 @@
{% extends "base" %}
{% import "macros" as macros %}
{% block title %}
{{ "Login" | _ }}
@@ -10,8 +11,8 @@
<p>{{ message }}</p>
{% endif %}
<form method="post">
{{ macros::input(name="email_or_name", label="Username or email", errors=errors, form=form) }}
{{ macros::input(name="password", label="Password", errors=errors, form=form, type="password") }}
{{ macros::input(name="email_or_name", label="Username or email", errors=errors, form=form, props='minlenght="1"') }}
{{ macros::input(name="password", label="Password", errors=errors, form=form, type="password", props='minlenght="8"') }}
<input type="submit" value="{{ "Login" | _ }}" />
</form>
+3 -3
View File
@@ -8,10 +8,10 @@
{% block content %}
<h1>{{ "Create an account" | _ }}</h1>
<form method="post">
{{ macros::input(name="username", label="Username", errors=errors, form=form) }}
{{ macros::input(name="username", label="Username", errors=errors, form=form, props='minlenght="1"') }}
{{ macros::input(name="email", label="Email", errors=errors, form=form, type="email") }}
{{ macros::input(name="password", label="Password", errors=errors, form=form, type="password") }}
{{ macros::input(name="password_confirmation", label="Password confirmation", errors=errors, form=form, type="password") }}
{{ macros::input(name="password", label="Password", errors=errors, form=form, type="password", props='minlenght="8"') }}
{{ macros::input(name="password_confirmation", label="Password confirmation", errors=errors, form=form, type="password", props='minlenght="8"') }}
<input type="submit" value="{{ "Create account" | _ }}" />
</form>