Class: SimpleForm::Inputs::Base
- Inherits:
-
Object
- Object
- SimpleForm::Inputs::Base
- Extended by:
- SimpleForm::I18nCache
- Includes:
- Components::Errors, Components::HTML5, Components::Hints, Components::LabelInput, Components::Maxlength, Components::MinMax, Components::Pattern, Components::Placeholders, Components::Readonly, Helpers::Autofocus, Helpers::Disabled, Helpers::Readonly, Helpers::Required, Helpers::Validators
- Defined in:
- lib/simple_form/inputs/base.rb
Direct Known Subclasses
BlockInput, BooleanInput, CollectionInput, DateTimeInput, FileInput, HiddenInput, NumericInput, PasswordInput, StringInput, TextInput
Instance Attribute Summary (collapse)
-
- (Object) attribute_name
readonly
Returns the value of attribute attribute_name.
-
- (Object) column
readonly
Returns the value of attribute column.
-
- (Object) html_classes
readonly
Returns the value of attribute html_classes.
-
- (Object) input_html_classes
readonly
Returns the value of attribute input_html_classes.
-
- (Object) input_html_options
readonly
Returns the value of attribute input_html_options.
-
- (Object) input_type
readonly
Returns the value of attribute input_type.
-
- (Object) options
readonly
Returns the value of attribute options.
-
- (Object) reflection
readonly
Returns the value of attribute reflection.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) additional_classes
-
- (Base) initialize(builder, attribute_name, column, input_type, options = {})
constructor
A new instance of Base.
- - (Object) input
- - (Object) input_class
- - (Object) input_options
Methods included from SimpleForm::I18nCache
get_i18n_cache, i18n_cache, reset_i18n_cache
Methods included from Components::Readonly
Methods included from Components::Placeholders
#placeholder, #placeholder_text
Methods included from Components::Pattern
Methods included from Components::MinMax
Methods included from Components::Maxlength
Methods included from Components::LabelInput
Methods included from Components::HTML5
#has_required?, #html5, #html5?
Methods included from Components::Hints
Methods included from Components::Errors
Methods included from Helpers::Validators
Constructor Details
- (Base) initialize(builder, attribute_name, column, input_type, options = {})
A new instance of Base
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/simple_form/inputs/base.rb', line 50 def initialize(builder, attribute_name, column, input_type, = {}) super = .dup @builder = builder @attribute_name = attribute_name @column = column @input_type = input_type @reflection = .delete(:reflection) @options = .reverse_merge!(self.class.) @required = calculate_required # Notice that html_options_for receives a reference to input_html_classes. # This means that classes added dynamically to input_html_classes will # still propagate to input_html_options. @html_classes = SimpleForm.additional_classes_for(:input) { additional_classes } @input_html_classes = @html_classes.dup @input_html_options = (:input, input_html_classes).tap do |o| o[:readonly] = true if has_readonly? o[:disabled] = true if has_disabled? o[:autofocus] = true if has_autofocus? end end |
Instance Attribute Details
- (Object) attribute_name (readonly)
Returns the value of attribute attribute_name
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def attribute_name @attribute_name end |
- (Object) column (readonly)
Returns the value of attribute column
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def column @column end |
- (Object) html_classes (readonly)
Returns the value of attribute html_classes
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def html_classes @html_classes end |
- (Object) input_html_classes (readonly)
Returns the value of attribute input_html_classes
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def input_html_classes @input_html_classes end |
- (Object) input_html_options (readonly)
Returns the value of attribute input_html_options
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def @input_html_options end |
- (Object) input_type (readonly)
Returns the value of attribute input_type
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def input_type @input_type end |
- (Object) options (readonly)
Returns the value of attribute options
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def @options end |
- (Object) reflection (readonly)
Returns the value of attribute reflection
24 25 26 |
# File 'lib/simple_form/inputs/base.rb', line 24 def reflection @reflection end |
Class Method Details
+ (Object) disable(*keys)
38 39 40 41 42 |
# File 'lib/simple_form/inputs/base.rb', line 38 def self.disable(*keys) = self..dup keys.each { |key| [key] = false } self. = end |
+ (Object) enable(*keys)
32 33 34 35 36 |
# File 'lib/simple_form/inputs/base.rb', line 32 def self.enable(*keys) = self..dup keys.each { |key| .delete(key) } self. = end |
Instance Method Details
- (Object) additional_classes
83 84 85 |
# File 'lib/simple_form/inputs/base.rb', line 83 def additional_classes @additional_classes ||= [input_type, required_class, readonly_class, disabled_class].compact end |
- (Object) input
75 76 77 |
# File 'lib/simple_form/inputs/base.rb', line 75 def input raise NotImplementedError end |
- (Object) input_class
87 88 89 |
# File 'lib/simple_form/inputs/base.rb', line 87 def input_class "#{lookup_model_names.join("_")}_#{reflection_or_attribute_name}" end |
- (Object) input_options
79 80 81 |
# File 'lib/simple_form/inputs/base.rb', line 79 def end |