Class: SimpleFormExtension::Inputs::ColorInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
lib/simple_form_extension/inputs/color_input.rb

Instance Method Summary collapse

Instance Method Details

#alignObject



32
33
34
# File 'lib/simple_form_extension/inputs/color_input.rb', line 32

def align
  options[:align].presence || :right
end

#formatObject



28
29
30
# File 'lib/simple_form_extension/inputs/color_input.rb', line 28

def format
  options[:format].presence || :hex
end

#input(wrapper_options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simple_form_extension/inputs/color_input.rb', line 6

def input(wrapper_options = nil)
  input_html_options[:class] << "colorpicker form-control"

  input_html_options[:data] ||= {}
  input_html_options[:data].merge!(
    colorpicker: true,
    format: format,
    align: align
  )

  # Fetch value
  color = object.send(attribute_name)

  (:div, class: 'input-group color', data: { :'colorpicker-wrapper' => true }) do
    @builder.text_field(attribute_name, input_html_options) +

    (:span, class: 'input-group-addon') do
      (:i, '')
    end
  end
end