xmon/color-picker-type-bundle

ColorPickerTypeBundle 扩展 Symfony2 表单类型,创建一个新的 ColorPicker 表单类型,用于显示 JavaScript 颜色选择器。

安装数: 32,066

依赖关系: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 8

开放问题: 7

语言:JavaScript

类型:symfony-bundle

v1.0.6 2017-06-16 08:36 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:31:05 UTC


README

ColorPickerTypeBundle 扩展 Symfony2/3 表单类型,创建一个新的 ColorPicker 表单类型,用于显示 JavaScript 颜色选择器。

此包使用 jscolor

安装

$ php composer.phar require xmon/color-picker-type-bundle

将 Bundle 添加到您的应用程序内核

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Xmon\ColorPickerTypeBundle\XmonColorPickerTypeBundle(),
        // ...
    );
}

配置

将 ColorPickerTypeBundle 添加到 assetic

# app/config/config.yml
# Assetic Configuration
assetic:
    bundles:        [ 'XmonColorPickerTypeBundle' ]

[SYMFONY 2] 包含布局的模板。

您可以在自己的 Bundle 中修改模板。

# your config.yml
twig:
    form:
        resources:
            # This uses the default - you can put your own one here
            - 'XmonColorPickerTypeBundle:Form:fields.html.twig'

[SYMFONY 3] 包含布局的模板。

您可以在自己的 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;

}

如果您想更改默认消息,请尝试以下操作

    /**
     * @XmonAssertColor\HexColor(
     *      message = "Custom message for value (%color%)."
     * )
     */

[SYMFONY 2] 如何在表单中使用。

$builder->add('fieldName', 'xmon_color_picker')

[SYMFONY 3] 如何在表单中使用。

use Xmon\ColorPickerTypeBundle\Form\Type\ColorPickerType;
...
$builder->add('fieldName', ColorPickerType::class)
...

此表单类型可以与 SonataAdminBundle 无问题地使用

致谢