Module: GenericFormFor::Inputs::Base
- Extended by:
- ActiveSupport::Autoload
- Includes:
- GenericFormFor::I18n, ErrorMessage, Hint, Label, Validations
- Included in:
- BooleanInput, EmailInput, FileInput, HiddenInput, NumberInput, PasswordInput, PhoneInput, RangeInput, SearchInput, SelectInput, StringInput, TextInput, UrlInput
- Defined in:
- lib/generic_form_for/inputs/base.rb,
lib/generic_form_for/inputs/base/hint.rb,
lib/generic_form_for/inputs/base/label.rb,
lib/generic_form_for/inputs/base/number.rb,
lib/generic_form_for/inputs/base/string.rb,
lib/generic_form_for/inputs/base/placeholder.rb,
lib/generic_form_for/inputs/base/validations.rb,
lib/generic_form_for/inputs/base/error_message.rb
Defined Under Namespace
Modules: ErrorMessage, Hint, Label, Number, Placeholder, String, Validations
Instance Attribute Summary collapse
-
#builder ⇒ Object
Returns the value of attribute builder.
-
#column ⇒ Object
Returns the value of attribute column.
-
#method ⇒ Object
Returns the value of attribute method.
-
#object ⇒ Object
Returns the value of attribute object.
-
#object_name ⇒ Object
Returns the value of attribute object_name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #autofocus? ⇒ Boolean
- #default_input_options ⇒ Object
- #form_builder_options ⇒ Object
- #initialize(builder, template, object, object_name, method, column, options) ⇒ Object
- #input_html_class ⇒ Object
- #input_html_options ⇒ Object
- #input_options ⇒ Object
- #merge_html_options(runtime_options, config_options) ⇒ Object
- #to_html ⇒ Object
- #wrap_in(*args, &block) ⇒ Object
Methods included from ErrorMessage
#error_html, #error_html_options, #errors, #errors?, #render_error?
Methods included from Label
#label_html, #label_html_options, #label_text, #render_label?, #requirement_text, #translated_label
Methods included from Validations
#decimals, #limit, #limits_from_validations, #maximal_number, #minimal_number, #required?, #required_from_validations?
Methods included from Hint
#hint_html, #hint_html_options, #hint_text, #render_hint?
Methods included from GenericFormFor::I18n
#translate, #translate_action, #translate_hint, #translate_label, #translate_legend, #translate_placeholder
Instance Attribute Details
#builder ⇒ Object
Returns the value of attribute builder.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def builder @builder end |
#column ⇒ Object
Returns the value of attribute column.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def column @column end |
#method ⇒ Object
Returns the value of attribute method.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def method @method end |
#object ⇒ Object
Returns the value of attribute object.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def object @object end |
#object_name ⇒ Object
Returns the value of attribute object_name.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def object_name @object_name end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def @options end |
#template ⇒ Object
Returns the value of attribute template.
16 17 18 |
# File 'lib/generic_form_for/inputs/base.rb', line 16 def template @template end |
Instance Method Details
#autofocus? ⇒ Boolean
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generic_form_for/inputs/base.rb', line 63 def autofocus? if .key?(:autofocus) if [:autofocus] template.autofocus = false true else false end else return false unless template.autofocus template.autofocus = false true end end |
#default_input_options ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/generic_form_for/inputs/base.rb', line 43 def { :autofocus => autofocus?, :required => required?, :class => input_html_class } end |
#form_builder_options ⇒ Object
59 60 61 |
# File 'lib/generic_form_for/inputs/base.rb', line 59 def [:collection, :required, :label, :as, :hint, :wrapper_html, :label_html, :error_html, :class, :autofocus] end |
#initialize(builder, template, object, object_name, method, column, options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generic_form_for/inputs/base.rb', line 18 def initialize(builder, template, object, object_name, method, column, ) @builder = builder @template = template @object = object @object_name = object_name @method = method @column = column @options = .dup @first_wrapper_class = "#{[:as]}-input" end |
#input_html_class ⇒ Object
51 52 53 |
# File 'lib/generic_form_for/inputs/base.rb', line 51 def input_html_class ([[:as]] + [*[:class]] + [('errors' if errors?)]).compact.join(" ").strip end |
#input_html_options ⇒ Object
39 40 41 |
# File 'lib/generic_form_for/inputs/base.rb', line 39 def .merge([:html] || {}).merge() end |
#input_options ⇒ Object
55 56 57 |
# File 'lib/generic_form_for/inputs/base.rb', line 55 def .except(*) end |
#merge_html_options(runtime_options, config_options) ⇒ Object
34 35 36 37 |
# File 'lib/generic_form_for/inputs/base.rb', line 34 def (,) [:class] = [*[:class], *[:class]].compact.join(' ').strip .merge() end |
#to_html ⇒ Object
29 30 31 32 |
# File 'lib/generic_form_for/inputs/base.rb', line 29 def to_html instance_exec &builder.input_wrapper_proc "" end |
#wrap_in(*args, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/generic_form_for/inputs/base.rb', line 6 def wrap_in(*args, &block) = args.first.is_a?(Hash) ? args.pop : {} [:class] = [@first_wrapper_class, *[:class], *([:wrapper_html]||{})[:class]].join(' ').strip .merge!((.delete(:wrapper_html) || {}).except(:class)) @first_wrapper_class = nil template.concat( template.content_tag(.delete(:tag) || :div, ) do template.capture(&block) if block_given? end.html_safe) end |