Class: SimpleForm::Inputs::Base
- Inherits:
-
Object
- Object
- SimpleForm::Inputs::Base
- Extended by:
- SimpleForm::I18nCache
- Includes:
- Components::Errors, Components::Hints, Components::LabelInput, Components::Placeholders, Components::Wrapper
- Defined in:
- lib/simple_form/inputs/base.rb
Direct Known Subclasses
BlockInput, BooleanInput, CollectionInput, DateTimeInput, HiddenInput, MappingInput, NumericInput, StringInput
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
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#input_html_options ⇒ Object
readonly
Returns the value of attribute input_html_options.
-
#input_type ⇒ Object
readonly
Returns the value of attribute input_type.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Instance Method Summary collapse
-
#initialize(builder, attribute_name, column, input_type, options = {}) ⇒ Base
constructor
A new instance of Base.
- #input ⇒ Object
- #input_html_classes ⇒ Object
- #input_options ⇒ Object
- #render ⇒ Object
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
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, = {}) @builder = builder @attribute_name = attribute_name @column = column @input_type = input_type @reflection = .delete(:reflection) @options = @input_html_options = (: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_name ⇒ Object (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 |
#column ⇒ Object (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_options ⇒ Object (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 end |
#input_type ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/simple_form/inputs/base.rb', line 18 def @options end |
#reflection ⇒ Object (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
#input ⇒ Object
37 38 39 |
# File 'lib/simple_form/inputs/base.rb', line 37 def input raise NotImplementedError end |
#input_html_classes ⇒ Object
45 46 47 |
# File 'lib/simple_form/inputs/base.rb', line 45 def input_html_classes [input_type, required_class] end |
#input_options ⇒ Object
41 42 43 |
# File 'lib/simple_form/inputs/base.rb', line 41 def end |
#render ⇒ Object
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 [component] == false rendered = send(component) content.safe_concat rendered.to_s if rendered end wrap(content) end |