Download the PHP package j-ben87/parsley-bundle without Composer
On this page you can find all versions of the php package j-ben87/parsley-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download j-ben87/parsley-bundle
More information about j-ben87/parsley-bundle
Files in j-ben87/parsley-bundle
Package parsley-bundle
Short Description Convert Symfony constraints into data-attributes for client-side validation with Parsley.
License MIT
Informations about the package parsley-bundle
ParsleyBundle
Convert Symfony constraints into data-attributes for client-side validation with Parsley.
Installation
Install the bundle with composer:
Install Parsley library: http://parsleyjs.org/doc/index.html#installation
Configuration
The bundle exposes a basic configuration:
Usage
Form constraints
Create a FormType
.
Any supported constraints you have defined on your form will automatically be turned into Parsley data-attributes.
Yes, it's that simple!
Results in:
data-class
constraints
Create a FormType
and configure its data-class
option.
Any supported constraint you have defined on your class will automatically be turned into Parsley data-attributes.
Here again, it's incredibly simple!
And
Results in:
Notice: if you define the same constraint on both the FormType
and the configured data-class
, the FormType
constraint will override the one configured on the data-class
.
Internals
The ParsleyTypeExtension
is where all the magic happens.
It gathers all Symfony constraints thanks to registered readers and turn them into Parsley constraints through factories.
It uses the special ChainFactory
to automatically find the first factory that supports the given Symfony constraint.
Finally it normalizes the Parsley constraint into data-attributes and merge them with the FormView
attributes.
Extending the bundle
You can easily add more constraints by:
- creating a constraint that extends the abstract class
JBen87\ParsleyBundle\Constraint\Constraint
- creating a factory that implements the interface
JBen87\ParsleyBundle\Constraint\Factory\FactoryInterface
Your factory will be automatically registered to be used by the ChainFactory
service.
Supported constraints
The following Symfony constraints are currently supported:
- Symfony\Component\Validator\Constraints\Date
- Symfony\Component\Validator\Constraints\DateTime
- Symfony\Component\Validator\Constraints\Email
- Symfony\Component\Validator\Constraints\GreaterThan
- Symfony\Component\Validator\Constraints\GreaterThanOrEqual
- Symfony\Component\Validator\Constraints\Length
- Symfony\Component\Validator\Constraints\LessThan
- Symfony\Component\Validator\Constraints\LessThanOrEqual
- Symfony\Component\Validator\Constraints\NotBlank
- Symfony\Component\Validator\Constraints\Range
- Symfony\Component\Validator\Constraints\Time
- Symfony\Component\Validator\Constraints\Type
- Symfony\Component\Validator\Constraints\Url
What's next
- Support more constraints
- Support group validation
All versions of parsley-bundle with dependencies
psr/log Version ^1.1|^2.0|^3.0
symfony/form Version ^5.4|^6.0
symfony/framework-bundle Version ^5.4|^6.0
symfony/serializer Version ^5.4|^6.0
symfony/validator Version ^5.4|^6.0