The ColorPickerTypeBundle
extends Symfony2/3
form types,
creates a new ColorPicker
form type, to display a javascript color picker.
This Bundle use jscolor.
$ php composer.phar require xmon/color-picker-type-bundle
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Xmon\ColorPickerTypeBundle\XmonColorPickerTypeBundle(),
// ...
);
}
# app/config/config.yml
# Assetic Configuration
assetic:
bundles: [ 'XmonColorPickerTypeBundle' ]
You can modify the template in your own bundle.
# your config.yml
twig:
form:
resources:
# This uses the default - you can put your own one here
- 'XmonColorPickerTypeBundle:Form:fields.html.twig'
You can modify the template in your own bundle.
# your config.yml
twig:
form_themes:
# This uses the default - you can put your own one here
- 'XmonColorPickerTypeBundle:Form:fields.html.twig'
// src/AppBundle/Entity/MyEntity.php
use Symfony\Component\Validator\Constraints as Assert;
use Xmon\ColorPickerTypeBundle\Validator\Constraints as XmonAssertColor;
class MyEntity
{
/**
* @ORM\Column(type="string", length=6, nullable=true)
* @XmonAssertColor\HexColor()
*/
public $fieldName;
}
If you want change default message, try this:
/**
* @XmonAssertColor\HexColor(
* message = "Custom message for value (%color%)."
* )
*/
$builder->add('fieldName', 'xmon_color_picker')
use Xmon\ColorPickerTypeBundle\Form\Type\ColorPickerType;
...
$builder->add('fieldName', ColorPickerType::class)
...
This form type can be used without any problem with SonataAdminBundle
- Thanks project used by this one:
- Thanks project by inspiration: