Bounty available!

It has been a while and this question still does not have any answers. Answer this question and get additional +229 points of karma/reputation if the original poster accepts your reply as correct answer

How to loop through form validation messages in volt?

I have in my volt template...

{{ this.flashSession.output() }}
{{ form.messages('username') }}
{{ form.messages('password') }}
{{ form.messages('confirmPassword') }}

This is in the form file...

public function messages($name)
    {
        if ($this->hasMessagesFor($name)) {
            foreach ($this->getMessagesFor($name) as $message) {
                $this->flash->error($message);
            }
        }
    }

It seems I have to put a form.messages for every field in the form or they wont print/render. My flash is using DI direct and I have a DI flashSession setup for use before redirects too.

Is there an easier way in volt to just loop through ALL available form.messages IF they exist and print/render them?

edited 25d ago

I think i solved this ... i made 2 functions. One for printing validation errors from a specific field. And one for printing all of them. Use one or the other.

In the form... class SomeForm extends Form

public function message($name)
    {
        if ($this->hasMessagesFor($name)) {
            foreach ($this->getMessagesFor($name) as $message) {
                $this->flash->error($message);
            }
        }
    }
    public function messages()
    {
        foreach ($this->getMessages() as $field => $message) {
            $this->flash->error($message);
        }
    }

in the volt...

{{ form.messages() }}