JsFormValidatorBundle icon indicating copy to clipboard operation
JsFormValidatorBundle copied to clipboard

Difference in 'validation_groups' inheritance to server side component

Open hanneskaeufler opened this issue 10 years ago • 4 comments

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 avatar Mar 18 '14 16:03 hanneskaeufler

@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.

jumale avatar Apr 03 '14 16:04 jumale

hey, yeah that looks like the case I was describing. Let me try to figure this out over the weekend ... thanks for investigating!

hanneskaeufler avatar Apr 03 '14 19:04 hanneskaeufler

@hanneskaeufler Did you solve it?

66Ton99 avatar Mar 12 '15 18:03 66Ton99

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',
    ]);
}

hanneskaeufler avatar Mar 13 '15 08:03 hanneskaeufler