Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array Validations not showing in twig #41

Open
lcabre opened this issue Jun 23, 2020 · 0 comments
Open

Array Validations not showing in twig #41

lcabre opened this issue Jun 23, 2020 · 0 comments

Comments

@lcabre
Copy link

lcabre commented Jun 23, 2020

Hi @barryvdh,
First of all, thank you very much for the package!, it's helping me a lot with a new project.

Like de title says, i need some guide to figure out why i cant get array validations errors in twig.
I can see those errors in blade ViewErrorBag, but not in twig.

Here a simple example:

web.php

Route::any('/test', 'FormController@demo');

FormController.php

public function demo(Request $request){
        $form = $this->createFormBuilder(null)
            ->add('name', TextType::class)
            ->add('file', FileType::class, [
                'multiple' => true
            ])
            ->add('save', SubmitType::class, ['label' => 'Save'])
            ->getForm();

        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $this->validateForm($form, $request, [
                'name' => 'required|min:10',
                "file" => "required|max:2",
                "file.*" => "file|max:1024|mimes:png"//Can't get this validations errors in twig
            ]);
            dd($form->getData());
        }

        return view('formularios.form_test', ['form' => $form->createView()]);
    }

form_test.blade.php

...
<div class="container">
        <div class="row">
            <div class="col-md-12">
                @formStart($form, [ 'attr' => ['autocomplete' => 'off']])
                @formWidget($form)
                @formEnd($form)
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                @if ($errors->any()) //to check in ViewErrorBag
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif
            </div>
        </div>
    </div>
...

And, for example if I add three jpg files (the validation only accept png), this is what i get:

image

As you can see, twig only shows the 'file' validation, but not the 'file.*' one.
Any help would be appreciated.

Regards,
Leo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant