validation_groups can be a closure #22

Closed
toooni opened this Issue Aug 31, 2012 · 9 comments

Projects

None yet

3 participants

@toooni
toooni commented Aug 31, 2012

since Symfony 2.1 the validation_groups of the form view can be closures (http://symfony.com/doc/master/book/forms.html#groups-based-on-submitted-data).
It would be nice if the APYJsFormValidationBundle can be used with them too... at the moment there is thrown an error as followed:

An exception has been thrown during the rendering of a template ("Warning: in_array() expects parameter 2 to be array, object given in .../vendor/apy/jsfv-bundle/APY/JsFormValidationBundle/EventListener/ValidationGroupsListener.php line 35") in The Bundle::template.html.twig at line xx.

@Abhoryo
Owner
Abhoryo commented Aug 31, 2012

Ok.

@Abhoryo
Owner
Abhoryo commented Aug 31, 2012

For now I don't have access to the form to do this.

@toooni
toooni commented Aug 31, 2012

i just looked a bit into it and maybe it isn't possible to realize something like this in a simple way :S

@Abhoryo
Owner
Abhoryo commented Aug 31, 2012

The closure for the validation_group needs a Form object but we have only the FormView object.

If your code doesn't need this form object in the closure, we can pass a fake Form object.

@recipe
Collaborator
recipe commented Aug 31, 2012

The problem is not misrepresented that the form is not available but that closure is called on form post-bind event.
We generate client-side javascript using any available information which can be retrieved before the form is rendered.

@toooni
toooni commented Aug 31, 2012

yes.. so there is no simple way.. the "form object" is what is needed inside the closure.. else it doesn't make sense to have one..
the only (very complex) solution is to use ajax calls for this.. client-side validation using closures in validation_groups is impossible..

@recipe
Collaborator
recipe commented Aug 31, 2012

First of all we should fix code to avoid error messages. After that, you'll be able at least use custom js code.

@recipe
Collaborator
recipe commented Aug 31, 2012

In this bundle validation_groups is used only for filtering the fields, that should not be checked.

@recipe recipe pushed a commit to recipe/APYJsFormValidationBundle that referenced this issue Aug 31, 2012
Vitaliy Demidov Fix error issue #22
If user uses Closure as validation_constraint value, this won't exclude
anyone constraint from client-side javascript validation.
Implemented ValidationGroupsListenerTest.
be403e9
@Abhoryo
Owner
Abhoryo commented Sep 3, 2012

Are we close this issue ?

@toooni toooni closed this Sep 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment