Class: Effective::FormInput

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

Constant Summary collapse

BLANK =
''.html_safe
EXCLUSIVE_CLASS_PREFIXES =

None

[]
EXCLUSIVE_CLASS_SUFFIXES =
['-primary', '-secondary', '-success', '-danger', '-warning', '-info', '-light', '-dark']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, builder:, html_options: nil) ⇒ FormInput

So this takes in the options for an entire form group.



13
14
15
16
17
18
19
20
# File 'app/models/effective/form_input.rb', line 13

def initialize(name, options, builder:, html_options: nil)
  @builder = builder
  @template = builder.template

  @name = name
  @options = extract_options!(options, html_options: html_options)
  apply_input_options!
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/effective/form_input.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'app/models/effective/form_input.rb', line 3

def options
  @options
end

Instance Method Details

#feedback_optionsObject



45
46
47
48
49
50
51
52
# File 'app/models/effective/form_input.rb', line 45

def feedback_options
  case layout
  when :inline
    false
  else
    { valid: { class: 'valid-feedback' }, invalid: { class: 'invalid-feedback' } }
  end
end

#hint_optionsObject



54
55
56
57
58
59
60
61
# File 'app/models/effective/form_input.rb', line 54

def hint_options
  case layout
  when :inline
    { tag: :small, class: 'text-muted', id: "#{tag_id}_hint" }
  else
    { tag: :small, class: 'form-text text-muted', id: "#{tag_id}_hint" }
  end
end

#input_group_optionsObject



22
23
24
# File 'app/models/effective/form_input.rb', line 22

def input_group_options
  { input_group: { class: 'input-group' }, prepend: false, append: false }
end

#input_html_optionsObject



26
27
28
# File 'app/models/effective/form_input.rb', line 26

def input_html_options
  { class: 'form-control' }
end

#input_js_optionsObject



30
31
32
# File 'app/models/effective/form_input.rb', line 30

def input_js_options
  {}
end

#label_optionsObject



34
35
36
37
38
39
40
41
42
43
# File 'app/models/effective/form_input.rb', line 34

def label_options
  case layout
  when :horizontal
    { class: 'col-sm-2 col-form-label'}
  when :inline
    { class: 'sr-only' }
  else
    { }
  end
end

#to_html(&block) ⇒ Object



72
73
74
# File 'app/models/effective/form_input.rb', line 72

def to_html(&block)
  wrap(&block)
end

#wrapper_optionsObject



63
64
65
66
67
68
69
70
# File 'app/models/effective/form_input.rb', line 63

def wrapper_options
  case layout
  when :horizontal
    { class: 'form-group row' }
  else
    { class: 'form-group' }
  end
end