Skip to content

Latest commit

 

History

History
executable file
·
49 lines (35 loc) · 1.24 KB

2_1.md

File metadata and controls

executable file
·
49 lines (35 loc) · 1.24 KB

2.1 Enabling and Disabling validation

JavaScript validation is enabled by default for all forms. The js_validation option can be set at three levels:

Globally

Disable validation for all forms:

# config/packages/fp_js_form_validator.yaml
fp_js_form_validator:
    js_validation: false

For a form type

Override the global setting for a specific form type:

<?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class UserType extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'js_validation' => false, // Disable for this form only
        ]);
    }
}

When the form option is not explicitly set (i.e., it is null), the form inherits the global configuration value. This allows you to:

  • Disable validation globally (js_validation: false) and then enable it only for selected forms by setting 'js_validation' => true on those forms.
  • Enable validation globally (the default) and disable it for specific forms by setting 'js_validation' => false on those forms.

For a field

See disable validation for a specified field.