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: false如果
availableColors字段未在 YAML 文件中定义,颜色选择器将使用一组 20 种默认颜色。
使用 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']
}