Fix off-by-one, improve style in forms example.

This commit is contained in:
Steven Murdoch 2023-06-14 13:51:18 +02:00 committed by Sergio Benitez
parent 260e671d43
commit 11c9c3cbcd
2 changed files with 18 additions and 9 deletions

View File

@ -13,16 +13,25 @@
margin: 0 auto;
padding: 20px 10px;
}
h1 {
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>Form Example</h1>
{% if errors | length > 1 %}
<small class="text-error" style="margin-top: -20px">
{{ errors | length }} field(s) have errors
</small>
{% if errors | length > 0 %}
<div class="row">
<div class="col">
<small class="text-error">
error: {{ errors | length }} field{{ errors | length | pluralize }}
failed to validate
</small>
</div>
</div>
{% endif %}
<form action="/" method="post" enctype="multipart/form-data">

View File

@ -2,7 +2,7 @@
{%- if name in values -%}
{{- values | get(key=name) | first -}}
{%- endif -%}
{% endmacro %}
{% endmacro value_for %}
{% macro errors_for(name) %}
{%- if name in errors -%}
@ -11,7 +11,7 @@
<p class="text-error is-marginless">{{ error.msg }}</p>
{% endfor %}
{%- endif -%}
{% endmacro %}
{% endmacro errors_for %}
{% macro input(type, label, name, value="") %}
<label for="{{ name }}">{{ label }}</label>
@ -37,7 +37,7 @@
>
{{ label }}
</label>
{% endmacro input %}
{% endmacro checkbox %}
{% macro textarea(label, name, placeholder="", max=250) %}
<label for="{{ name }}">{{ label }}</label>
@ -49,7 +49,7 @@
</textarea>
{{ self::errors_for(name=name) }}
{% endmacro input %}
{% endmacro textarea %}
{% macro select(label, name, options) %}
<label for="{{ name }}">{{ label }}</label>
@ -60,4 +60,4 @@
>{{ value }}</option>
{% endfor %}
</select>
{% endmacro input %}
{% endmacro select %}