statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

FR: Add inline error array to form tags #2090

Open dannyuk1982 opened 6 years ago

dannyuk1982 commented 6 years ago

With a form there are two arrays errors, which contains an array of all the errors, keys from 0...n, and an error array which has named keys to allow inline errors to be displayed.

For tags like user:forgot_password_form, user:login_form, user:register_form and user:reset_password_form there is no way to have inline errors as only the errors array exists.

reimar commented 5 years ago

If anyone is looking for a very hacky solution, try this:

{{ user:register_form }}
...
    <label for="password">Password</label>
    <input class="{{ if errors:0 | contains:Password or errors:1 | contains:Password or errors:2 | contains:Password }}invalid{{ /if }}" type="password" name="password" />
    <span>{{ if errors:0 | contains: Password or errors:1 | contains: Password or errors:2 | contains: Password }}Please provide a password{{ /if }}</span>
{{ /user:register_form }}

It’s really dirty and I feel guilty ;) I tried a slightly cleaner hack but unfortunately, it does not work at all:

{{ if (errors | in_array: Password) }}Please provide a password{{ /if }}