colorpicker - 渲染控件以选择一个十六进制颜色值。
color:
label: Background
type: colorpicker以下 字段属性 受支持且常用。
| Property | Description |
|---|---|
| label | a name when displaying the form field to the user. |
| default | specifies a default string value, optional. |
| comment | places a descriptive comment below the field. |
| availableColors | list of available colors as an array. |
| allowEmpty | allows empty input value. Default: false |
| allowCustom | allows selection of a custom color. Default: true |
| showAlpha | displays an opacity slider and sets an 8-digit hex code. Default: false |
| showInput | displays a text input next to the color picker and disables available colors. Default: false |
你可以通过将 availableColors 属性设置为十六进制颜色值的数组来定义预设颜色。 allowCustom 属性可用于禁用自定义颜色选择,并且这是可选的。
color:
label: Background
type: colorpicker
availableColors: ['#000000', '#111111', '#222222']
allowCustom: falseIf the
availableColorsfield in not defined in the YAML file, the colorpicker uses a set of 20 default colors.
使用 showAlpha 属性在颜色选择中包含不透明度,从而生成一个8位十六进制值。
color:
label: Background
type: colorpicker
showAlpha: true使用 showInput 属性在颜色旁边显示文本输入。此模式将禁用可用颜色并使选择和输入自定义十六进制颜色成为主要焦点。
color:
label: Primary Color
type: colorpicker
showInput: true可用颜色可以通过将 availableColors 设置为模型类中声明的方法名来从模型类中获取。此方法应返回一个十六进制颜色数组,其格式与上述示例相同。此方法的第一个参数是字段名,第二个是字段的当前值,第三个是整个表单的当前数据对象。
color:
label: Background
type: colorpicker
availableColors: myColorList在模型类中提供可用颜色:
public function myColorList($fieldName, $value, $formData)
{
return ['#000000', '#111111', '#222222']
}