Level51\ColorPicker\ColorPickerField
FormField showing a basic RGB color picker.
In RGB mode, the value will be stored in single database field as JSON string, e.g. {"R":"73","G":"128","B":"140"}.
In Hex mode, the value will be a single string - so no manipulation needed here.
Synopsis
class ColorPickerField
extends FormField
{
- // constants
- const MODE_RGB = 'rgb';
- const MODE_HEX = 'hex';
- // members
- private bool $showCheckbox = true;
- private string $mode = 'rgb';
- // methods
- public void Field()
- public string getPayload()
- public array getFrontendI18NPayload()
- public void setSubmittedValue()
- public $this setSubmittedRGBValue()
- public void validate()
- private bool validateRGBMode()
- private bool validateHexMode()
- public $this disableCheckbox()
- public $this setMode()
Hierarchy
Extends
- SilverStripe\Forms\FormField
Constants
Name | Value |
---|---|
MODE_RGB | 'rgb' |
MODE_HEX | 'hex' |
Members
private
- $mode — string
- $showCheckbox — Level51\ColorPicker\bool
Methods
private
- validateHexMode() — Validate the input in Hex mode, ensure that the value is a string with exactly 7 chars.
- validateRGBMode() — Validate the input in RGB mode, ensure that each value is between -1 and 255.
public
- Field()
- disableCheckbox() — Disable the "Add RGB color values" checkbox, so instantly show the color picker.
- getFrontendI18NPayload() — Get a list of all labels used within the frontend.
- getPayload() — Get the payload passed to the vue component.
- setMode() — Change the color picker mode, see MODE_ constants.
- setSubmittedRGBValue() — Turn the submitted rgb value (array with 3 single values) into a JSON string for storage.
- setSubmittedValue()
- validate()