Developed with love by KnpLabs Hire us for your project!
78

JsFormValidatorBundle

by formapro

The Javascript validation for sf2 forms

FpJsFormValidatorBundle

Build Status
Total Downloads

This module enables validation of the Symfony2 forms on the JavaScript side.
It converts form type constraints into JavaScript validation rules.

1 Installation

Upgrade from the previous version

1.1 Download FpJsFormValidatorBundle using composer

Run in terminal:
bash
$ php composer.phar require "fp/jsformvalidator-bundle":"dev-master"

1.2 Enable the bundle

Enable the bundle:
```php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new Fp\JsFormValidatorBundle\FpJsFormValidatorBundle(),
);
}
```

1.3 Enable javascript libraries

<html>
    <head>
        {{ include('FpJsFormValidatorBundle::javascripts.html.twig') }}
    </head>
    <body>

    </body>
</html>

1.4 Add routes

If you use the UniqueEntity constraint, then you have to include the next part to your routing config:
```yaml
//app/config/routing.yml

...

fp_js_form_validator:
resource: "@FpJsFormValidatorBundle/Resources/config/routing.xml"
prefix: /fp_js_form_validator
```
Make sure that your security settings do not prevent these routes.

2 Usage

After the previous steps the javascript validation will be enabled automatically for all your forms.

  1. Disabling validation
  2. If your forms are placed in sub-requests
  3. If you need to initialize JS validation for your forms separately, or by some event, in this case you need to follow these steps instead of the chapter 1.3

3 Customization

Preface

This bundle finds related DOM elements for each element of a symfony form and attach to it a special object-validator.
This object contains list of properties and methods which fully define the validation process for the related form element.
And some of those properties and methods can be changed to customize the validation process.

If you render forms with a some level of customization - read this note.

  1. Disable validation for a specified field
  2. Error display
  3. Get validation groups from a closure
  4. Getters validation
  5. The Callback constraint
  6. The Choice constraint. How to get the choices list from a callback
  7. Custom constraints
  8. Custom data transformers
  9. Checking the uniqueness of entities
  10. Form submit by Javasrcipt
  11. onValidate callback
  12. Run validation on custom event
  13. Collections validation
Copyright (C) 2014 by Forma-Pro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
fp_js_form_validator:
js_validation: true
routing:
check_unique_entity: fp_js_form_validator.check_unique_entity # Required
  • Merge pull request #62 from maarekj/patch-1
    By 66Ton99, 1 year ago
  • FIX typo in doc/3_10.md
    By maarekj, 2 years ago
  • Merge pull request #50 from formapro/JsFormValidatorBundle-47
    By , 2 years ago
  • Merge pull request #49 from tools4origins/master
    By jumale, 2 years ago
  • changes for special versions for sf2.3
    By jumale, 2 years ago
  • changes for special versions for sf2.3
    By jumale, 2 years ago
  • changes for special versions for sf2.3
    By jumale, 2 years ago
  • changes for special versions for sf2.3
    By jumale, 2 years ago
  • changes for special versions for sf2.3
    By jumale, 2 years ago
  • changes for special versions for sf2.3
    By jumale, 2 years ago
  • BasicConstraintsEntity - special version for sf2.3
    By jumale, 2 years ago
  • update for travis
    By jumale, 2 years ago
  • update for travis
    By jumale, 2 years ago
  • update for travis
    By jumale, 2 years ago
  • update for travis
    By jumale, 2 years ago
  • Correct typo
    By , 2 years ago
  • Correct typo
    By tools4origins, 2 years ago
  • #47 Empty choice type with expanded=true and multiple=false
    By jumale, 2 years ago
  • #47 Empty choice type with expanded=true and multiple=false
    By jumale, 2 years ago
  • #47 Empty choice type with expanded=true and multiple=false
    By jumale, 2 years ago
  • Merge pull request #48 from VaclavSir/patch-1
    By jumale, 2 years ago
  • #47 Empty choice type with expanded=true and multiple=false
    By jumale, 2 years ago
  • Update docs: JS side of custom constraint
    By , 2 years ago
  • Merge pull request #44 from formapro/JsFormValidatorBundle-43
    By jumale, 2 years ago
  • update .travis.yml
    By jumale, 2 years ago
  • update .travis.yml
    By jumale, 2 years ago
  • update .travis.yml
    By jumale, 2 years ago
  • #43 validation not work for forms loaded by ajax
    By jumale, 2 years ago
  • Merge pull request #39 from formapro/JsFormValidatorBundle-37
    By yury-maltsev, 2 years ago
  • JsFormValidatorBundle-37 Error mapping doesn't work
    By yury-maltsev, 2 years ago