Class: Effective::FormInputs::Checks
Constant Summary
Effective::FormInput::BLANK, Effective::FormInput::DEFAULT_FEEDBACK_OPTIONS, Effective::FormInput::DEFAULT_INPUT_GROUP_OPTIONS, Effective::FormInput::EMPTY_HASH, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES, Effective::FormInput::HORIZONTAL_LABEL_OPTIONS, Effective::FormInput::HORIZONTAL_WRAPPER_OPTIONS, Effective::FormInput::INLINE_LABEL_OPTIONS, Effective::FormInput::VERTICAL_WRAPPER_OPTIONS
Instance Attribute Summary
#name, #options
Instance Method Summary
collapse
#assign_options_collection!, #assign_options_collection_methods!, #collection_options, #custom?, #group_label_method, #group_method, #grouped?, #html_options, #initialize, #inline?, #label_method, #option_key_method, #option_value_method, #options_collection, #polymorphic?, #polymorphic_id_method, #polymorphic_id_value, #polymorphic_type_method, #polymorphic_type_value, #polymorphic_value, #translate, #value_method
#hint_options, #initialize, #input_group_options, #input_js_options, #label_options, #to_html
Instance Method Details
#actions? ⇒ Boolean
105
106
107
108
|
# File 'app/models/effective/form_inputs/checks.rb', line 105
def actions? return @actions unless @actions.nil?
@actions = (options[:input].delete(:actions) != false)
end
|
8
9
10
11
12
13
14
15
16
|
# File 'app/models/effective/form_inputs/checks.rb', line 8
def build_input(&block)
html = @builder.collection_check_boxes(name, options_collection, value_method, label_method, collection_options, item_input_options) { |builder| build_item(builder) }
if disabled? html = html.sub('<input type="hidden"', '<input type="hidden" disabled="disabled"').html_safe
end
html
end
|
#build_item(builder) ⇒ Object
80
81
82
83
|
# File 'app/models/effective/form_inputs/checks.rb', line 80
def build_item(builder)
item_id = unique_id(builder.object)
build_item_wrap { builder.check_box(id: item_id) + builder.label(item_label_options.merge(for: item_id)) }
end
|
#build_item_wrap(&block) ⇒ Object
85
86
87
88
89
90
91
|
# File 'app/models/effective/form_inputs/checks.rb', line 85
def build_item_wrap(&block)
if custom?
content_tag(:div, yield, class: 'custom-control custom-checkbox ' + (inline? ? 'custom-control-inline' : 'form-group'))
else
content_tag(:div, yield, class: 'form-check' + (inline? ? ' form-check-inline' : ''))
end
end
|
#build_label ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/models/effective/form_inputs/checks.rb', line 54
def build_label
return BLANK if options[:label] == false && !actions?
return BLANK if name.kind_of?(NilClass)
text = begin
if options[:label] == false
nil
elsif options[:label].key?(:text)
options[:label].delete(:text)
elsif object.present?
object.class.human_attribute_name(name)
end || BLANK
end.html_safe
actions = if !disabled? && actions?
content_tag(:div, class: 'effective-checks-actions text-muted') do
link_to('Select All', '#', 'data-effective-checks-all': true) + ' - ' + link_to('Select None', '#', 'data-effective-checks-none': true)
end
end
content_tag(:label, options[:label]) do
[text, actions].compact.join.html_safe
end
end
|
#build_wrapper(&block) ⇒ Object
18
19
20
21
22
23
24
|
# File 'app/models/effective/form_inputs/checks.rb', line 18
def build_wrapper(&block)
if layout == :horizontal
content_tag(:fieldset, content_tag(:div, yield, class: 'row'), options[:wrapper])
else
content_tag(:fieldset, yield, options[:wrapper])
end
end
|
#feedback_options ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'app/models/effective/form_inputs/checks.rb', line 37
def feedback_options
return false if layout == :inline
{
valid: { class: 'valid-feedback' }.compact,
invalid: { class: 'invalid-feedback' }.compact
}
end
|
46
47
48
49
50
51
52
|
# File 'app/models/effective/form_inputs/checks.rb', line 46
def input_html_options
if custom?
{ class: 'custom-control-input' }
else
{ class: 'form-check-input' }
end
end
|
93
94
95
|
# File 'app/models/effective/form_inputs/checks.rb', line 93
def item_input_options
options[:input].except(:inline, :custom, :required)
end
|
#item_label_options ⇒ Object
97
98
99
100
101
102
103
|
# File 'app/models/effective/form_inputs/checks.rb', line 97
def item_label_options
if custom?
{ class: 'custom-control-label' }
else
{ class: 'form-check-label' }
end
end
|
#wrapper_options ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'app/models/effective/form_inputs/checks.rb', line 26
def wrapper_options
{ class: [
'form-group effective-checks',
('no-feedback' unless feedback_options),
tag_id,
('is-invalid' if feedback_options && has_error?(name)),
('is-valid' if feedback_options && has_error? && !has_error?(name))
].compact.join(' ')
}
end
|