Class: Effective::FormInput

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

Constant Summary collapse

BLANK =
''.html_safe
EMPTY_HASH =
{}
EXCLUSIVE_CLASS_PREFIXES =

None

[]
EXCLUSIVE_CLASS_SUFFIXES =
['-primary', '-secondary', '-success', '-danger', '-warning', '-info', '-light', '-dark', '-link']
DEFAULT_INPUT_GROUP_OPTIONS =
{ input_group: { class: 'input-group' }, prepend: false, append: false }
HORIZONTAL_LABEL_OPTIONS =
{ class: 'col-sm-2 col-form-label'}
INLINE_LABEL_OPTIONS =
{ class: 'sr-only' }
DEFAULT_FEEDBACK_OPTIONS =
{ valid: { class: 'valid-feedback' }, invalid: { class: 'invalid-feedback' } }
HORIZONTAL_WRAPPER_OPTIONS =
{ class: 'form-group row' }
VERTICAL_WRAPPER_OPTIONS =
{ class: 'form-group' }

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.



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

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.



5
6
7
# File 'app/models/effective/form_input.rb', line 5

def name
  @name
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'app/models/effective/form_input.rb', line 5

def options
  @options
end

Instance Method Details

#feedback_optionsObject



59
60
61
62
63
64
65
66
# File 'app/models/effective/form_input.rb', line 59

def feedback_options
  case layout
  when :inline
    false
  else
    DEFAULT_FEEDBACK_OPTIONS
  end
end

#hint_optionsObject



68
69
70
71
72
73
74
75
# File 'app/models/effective/form_input.rb', line 68

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



36
37
38
# File 'app/models/effective/form_input.rb', line 36

def input_group_options
  DEFAULT_INPUT_GROUP_OPTIONS
end

#input_html_optionsObject



40
41
42
# File 'app/models/effective/form_input.rb', line 40

def input_html_options
  { class: 'form-control', id: tag_id }
end

#input_js_optionsObject



44
45
46
# File 'app/models/effective/form_input.rb', line 44

def input_js_options
  EMPTY_HASH
end

#label_optionsObject



48
49
50
51
52
53
54
55
56
57
# File 'app/models/effective/form_input.rb', line 48

def label_options
  case layout
  when :horizontal
    HORIZONTAL_LABEL_OPTIONS
  when :inline
    INLINE_LABEL_OPTIONS
  else
    EMPTY_HASH
  end
end

#to_html(&block) ⇒ Object



86
87
88
# File 'app/models/effective/form_input.rb', line 86

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

#wrapper_optionsObject



77
78
79
80
81
82
83
84
# File 'app/models/effective/form_input.rb', line 77

def wrapper_options
  case layout
  when :horizontal
    HORIZONTAL_WRAPPER_OPTIONS
  else
    VERTICAL_WRAPPER_OPTIONS
  end
end