Skip to content

Commit

Permalink
Fix off-by-one, improve style in forms example.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmurdoch authored and SergioBenitez committed Oct 27, 2023
1 parent 260e671 commit 11c9c3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 13 additions & 4 deletions examples/forms/templates/index.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
10 changes: 5 additions & 5 deletions examples/forms/templates/macros.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand All @@ -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>
Expand All @@ -37,7 +37,7 @@
>
{{ label }}
</label>
{% endmacro input %}
{% endmacro checkbox %}

{% macro textarea(label, name, placeholder="", max=250) %}
<label for="{{ name }}">{{ label }}</label>
Expand All @@ -49,7 +49,7 @@
</textarea>

{{ self::errors_for(name=name) }}
{% endmacro input %}
{% endmacro textarea %}

{% macro select(label, name, options) %}
<label for="{{ name }}">{{ label }}</label>
Expand All @@ -60,4 +60,4 @@
>{{ value }}</option>
{% endfor %}
</select>
{% endmacro input %}
{% endmacro select %}

0 comments on commit 11c9c3c

Please sign in to comment.