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

View File

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