Skip to content

Latest commit

 

History

History
55 lines (49 loc) · 1.13 KB

File metadata and controls

55 lines (49 loc) · 1.13 KB

3.3 Get validation groups from a closure

If you have defined validation groups as a callback:

namespace Acme\DemoBundle\Form;

class UserType extends AbstractType
{
    // ...

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(
            array(
                'data_class'        => 'Acme\DemoBundle\Entity\User',
                'validation_groups' => function () {
                        if (...) {
                            return array(...);
                        } else {
                            return array(...);
                        }
                    }
            )
        );
    }
}

Then you have to implement it on the JS side:

$('form#user').jsFormValidator({
    groups: function () {
        if (...) {
            return [...];
        } else {
            return [...];
        }
    }
});

Pure Javascript:

var field = document.getElementById('user');
FpJsFormValidator.customize(field, {
    groups: function () {
        if (...) {
            return [...];
        } else {
            return [...];
        }
    }
});