Class: SimpleForm::Inputs::Base

Inherits:
Object
  • Object
show all
Extended by:
SimpleForm::I18nCache
Includes:
Components::Errors, Components::Hints, Components::LabelInput, Components::Placeholders, Components::Wrapper
Defined in:
lib/simple_form/inputs/base.rb

Constant Summary collapse

ACTIONS =

When action is create or update, we still should use new and edit

{
  :create => :new,
  :update => :edit
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleForm::I18nCache

get_i18n_cache, i18n_cache, reset_i18n_cache

Methods included from Components::Wrapper

#wrap, #wrapper_class, #wrapper_error_class, #wrapper_html_options, #wrapper_tag

Methods included from Components::Placeholders

#has_placeholder?, #placeholder, #placeholder_present?, #placeholder_text

Methods included from Components::LabelInput

included, #label_input

Methods included from Components::Hints

#hint, #hint_html_options, #hint_tag, #hint_text

Methods included from Components::Errors

#error, #error_html_options, #error_method, #error_tag, #error_text

Constructor Details

#initialize(builder, attribute_name, column, input_type, options = {}) ⇒ Base

Returns a new instance of Base.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/simple_form/inputs/base.rb', line 23

def initialize(builder, attribute_name, column, input_type, options = {})
  @builder            = builder
  @attribute_name     = attribute_name
  @column             = column
  @input_type         = input_type
  @reflection         = options.delete(:reflection)
  @options            = options
  @input_html_options = html_options_for(:input, input_html_classes).tap do |o|
    o[:required]  = true if has_required?
    o[:disabled]  = true if disabled?
    o[:autofocus] = true if has_autofocus?
  end
end

Instance Attribute Details

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



18
19
20
# File 'lib/simple_form/inputs/base.rb', line 18

def attribute_name
  @attribute_name
end

#columnObject (readonly)

Returns the value of attribute column.



18
19
20
# File 'lib/simple_form/inputs/base.rb', line 18

def column
  @column
end

#input_html_optionsObject (readonly)

Returns the value of attribute input_html_options.



18
19
20
# File 'lib/simple_form/inputs/base.rb', line 18

def input_html_options
  @input_html_options
end

#input_typeObject (readonly)

Returns the value of attribute input_type.



18
19
20
# File 'lib/simple_form/inputs/base.rb', line 18

def input_type
  @input_type
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/simple_form/inputs/base.rb', line 18

def options
  @options
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



18
19
20
# File 'lib/simple_form/inputs/base.rb', line 18

def reflection
  @reflection
end

Instance Method Details

#inputObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/simple_form/inputs/base.rb', line 37

def input
  raise NotImplementedError
end

#input_html_classesObject



45
46
47
# File 'lib/simple_form/inputs/base.rb', line 45

def input_html_classes
  [input_type, required_class]
end

#input_optionsObject



41
42
43
# File 'lib/simple_form/inputs/base.rb', line 41

def input_options
  options
end

#renderObject



49
50
51
52
53
54
55
56
57
# File 'lib/simple_form/inputs/base.rb', line 49

def render
  content = "".html_safe
  components_list.each do |component|
    next if options[component] == false
    rendered = send(component)
    content.safe_concat rendered.to_s if rendered
  end
  wrap(content)
end