/** * Method to get the field input markup. * * @return string The field input markup. */ protected function getInput() { if (empty($this->value)) { // A color field can't be empty, we default to black. This is the same as the HTML5 spec. $this->value = '#000000'; } $this->value = '#' . ltrim($this->value, '#'); // Initialize some field attributes. $attributes = array('type' => 'text', 'value' => htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'), 'name' => $this->name, 'id' => $this->id, 'size' => $this->element['size'] ? (int) $this->element['size'] : '', 'maxlength' => $this->element['maxlength'] ? (int) $this->element['maxlength'] : '', 'class' => $this->element['class'] ? (string) $this->element['class'] : '', 'autocomplete' => (string) $this->element['autocomplete'] == 'off' ? 'off' : '', 'readonly' => (string) $this->element['readonly'] == 'true' ? 'readonly' : '', 'disabled' => (string) $this->element['disabled'] == 'true' ? 'disabled' : '', 'onchange' => $this->element['onchange'] ? (string) $this->element['onchange'] : ''); if (!$attributes['disabled']) { Behavior::colorpicker(); $attributes['class'] .= ' input-colorpicker'; } return '<span class="input-color"><input ' . $attr . ' /></span>'; }
/** * Displays a color picker control field * * @param string $name * @param string $value * @param array $options * @return string HTML markup for a calendar field */ public static function colorpicker($name, $value = null, $options = array()) { static $done; if ($done === null) { $done = array(); } $readonly = isset($options['readonly']) && $options['readonly'] == 'readonly'; $disabled = isset($options['disabled']) && $options['disabled'] == 'disabled'; $options['class'] = 'input-colorpicker'; $value = $value ? '#' . ltrim($value, '#') : ''; if (!$readonly && !$disabled) { $id = self::getIdAttribute($name, $options); // Only display the triggers once for each control. if (!in_array($id, $done)) { // Load the calendar behavior Behavior::colorpicker(); $done[] = $id; } return '<span class="input-color">' . self::text($name, $value, $options) . '</span>'; } return self::text($name . 'disabled', $value, $options) . self::hidden($name, $value, $options); }