massil / jsformvalidator-bundle
Javascript validation for sf2 forms.
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 56
Type:symfony-bundle
Requires
- php: >=5.3.2
- symfony/form: ^2.7|^3.0
- symfony/validator: ^2.7|^3.0
Requires (Dev)
- behat/mink-bundle: dev-master
- behat/mink-selenium2-driver: ^1.1.0
- doctrine/doctrine-bundle: ~1.4
- doctrine/orm: >=2.2.3
- phpunit/phpunit: 3.7.*
- ptcong/php-image-uploader: ^6.0
- satooshi/php-coveralls: 1.0.*
- se/selenium-server-standalone: 2.*
- symfony/assetic-bundle: >=2.5
- symfony/symfony: ^3.0
Suggests
- doctrine/doctrine-bundle: For the UniqueEntity validation
- doctrine/orm: For the UniqueEntity validation
- symfony/assetic-bundle: For easy enabling
- symfony/symfony: For using as a Symfony Bundle and for using a default ajax validation
README
This module enables validation of the Symfony 3 forms on the JavaScript side. It converts form type constraints into JavaScript validation rules.
If you have Symfony 2.8.* or 2.7.* - you need to use Version 1.3.* If you have Symfony 2.6.* or less - you need to use Version 1.2.*
1 Installation
1.1 Download FpJsFormValidatorBundle using composer
Run in terminal:
$ php composer.phar require "fp/jsformvalidator-bundle":"dev-master"
Or if you do not want to unexpected problems better to use exact version.
$ php composer.phar require "fp/jsformvalidator-bundle":"v1.4.*"
1.2 Enable the bundle
Enable the bundle:
// 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: 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.
- Disabling validation
- If your forms are placed in sub-requests
- 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.
- Disable validation for a specified field
- Error display
- Get validation groups from a closure
- Getters validation
- The Callback constraint
- The Choice constraint. How to get the choices list from a callback
- Custom constraints
- Custom data transformers
- Checking the uniqueness of entities
- Form submit by Javasrcipt
- onValidate callback
- Run validation on custom event
- Collections validation