Class: Effective::FormInput

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/form_input.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, object_name, template, method, opts) ⇒ FormInput

Returns a new instance of FormInput.



4
5
6
7
8
9
10
# File 'app/models/effective/form_input.rb', line 4

def initialize(object, object_name, template, method, opts)
  @object = object
  @object_name = object_name
  @template = template
  @method = method
  @opts = opts
end

Instance Method Details

#default_input_classes ⇒ Object



21
# File 'app/models/effective/form_input.rb', line 21

def default_input_classes; [] end

#default_input_js_options ⇒ Object



20
# File 'app/models/effective/form_input.rb', line 20

def default_input_js_options; {} end

#field_name ⇒ Object



12
13
14
# File 'app/models/effective/form_input.rb', line 12

def field_name
  "#{@object_name}[#{@method}]"
end

#options(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/effective/form_input.rb', line 23

def options(&block)
  @form_field_options ||= (
    (@opts || {}).tap do |options|
      options['data-input-js-options'] = {} unless options['data-input-js-options'].kind_of?(Hash)
      merge_class_options!(options)

      yield(options) if block_given?

      merge_input_js_options!(options)
      options.delete('data-input-js-options') if options['data-input-js-options'] == '{}'
    end
  )
end

#value ⇒ Object



16
17
18
# File 'app/models/effective/form_input.rb', line 16

def value
  options[:value] || (@object.send(@method) if @object.respond_to?(@method))
end