Abhoryo / APYJsFormValidationBundle

This bundle performs validations of a form in javascript. (i18n compatible and several javascript frameworks supported)
92 stars 23 forks source link

No formView objectin Twig's JsFormValidationFunction #26

Closed schingeldi closed 11 years ago

schingeldi commented 11 years ago

I have two projects. In one everything works fine, in the other there is no validation. I debugged it as far as I could and found out, that in

APY\JsFormValidationBundle\Twig\Extension\JsFormValidationTwigExtension:: JsFormValidationFunction the passed $formView is null. In my working project this is a object of Class FormView.

I debugged everything I could and before passing the created form form to my twig template, it is of type

Symfony\Component\Form\FormView

The form in the template is rendered fine.


{{ JSFV(form) }}
<form id="pageform" data-ajax='false' action="{{ path('mobile_register') }}" {{ form_enctype(form) }} method="POST" class="">

    {{ form_row(form.first_name) }}
    {{ form_row(form.last_name) }}
    {{ form_row(form.email_address) }}

    {{ form_errors(form) }}

    {{ form_rest(form)}}

    <div>
        <input type="submit" data-icon="arrow-r" data-theme="a" value="{{ 'registration.submit'|trans({}, 'profile') }}" />
    </div>
</form>

Does anyone have an idea how I could sove this? Any debugging suggestions?

recipe commented 11 years ago

Look to controller. Action method should return for the template something like this 'form' => $form->createView(),

schingeldi commented 11 years ago

Thanks for the fast reply. But this is what I checked before:

return array('form' => $form->createView());

And if it would not be a correct FormView, the template would not be able to render it, right?

Abhoryo commented 11 years ago

Maybe the order in your template. Maybe the form is null after rendering? Put the jsfv in first.

schingeldi commented 11 years ago

Hi. Thanks for all your help. I finally found the error. It was a misspelling of my form fields.

Entity field was

$firstName

form field was

first_name

And I had only three fields in my form, all having an underscore. I would have thought that I at least get an error, because of the names do not match, but nevertheless it was all my fault. Sorry for the confusion.

Abhoryo commented 11 years ago

Now, jquery don't generate errors when a field is not found.