JsFormValidatorBundle
JsFormValidatorBundle copied to clipboard
Difference in 'validation_groups' inheritance to server side component
There is a difference in how the bundle validation models inherit the validation_groups
option.
Again, considering a form like:
- form (validation_groups: Foo, Bar)
- step1: (type: form)
- tags: (type: collection, MyTagType)
- name: (constraints: NotBlank(validation_group: Bar))
The symfony form component validates the NotBlank constraint when I submit with Foo
and Bar
groups. The js component doesn´t.
If I go ahead and do
// MyTagType.php
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'validation_groups' => 'Bar',
]);
}
the js component also picks up on the constraints.
This should maybe be made consistent? Granted this is not your average form.
And by explicitly setting the validation_groups
on the MyTagType I can make it work.
@hanneskaeufler hi, could you help me reproduce this bug. I've created the parent form, child step1 subform that contains a collection of tags. Then I've created this controller. When I run it on my test environment, I see this error on both sides - symfony and JS. Could you try to test these files in your project and maybe change them to reach that bug, and send me changes.
Thanks.
hey, yeah that looks like the case I was describing. Let me try to figure this out over the weekend ... thanks for investigating!
@hanneskaeufler Did you solve it?
I worked around the difference by hardcoding the validation group in the setDefaultOptions
of the child type. Not ideal but works for me for now.
// MyTagType.php
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'validation_groups' => 'Bar',
]);
}