Class: Effective::FormLogics::HideIf
Instance Attribute Summary
#args
Instance Method Summary
collapse
#initialize, #input_js_options, #input_js_options_method_name, #tag_name
Instance Method Details
#hide? ⇒ Boolean
36
37
38
|
# File 'app/models/effective/form_logics/hide_if.rb', line 36
def hide?
(object.try(args.first) == args.second) || (object.try(args.first).to_s == args.second.to_s)
end
|
27
28
29
|
# File 'app/models/effective/form_logics/hide_if.rb', line 27
def input_logic_options
args.third.kind_of?(Hash) ? args.third : {}
end
|
#logic_options ⇒ Object
23
24
25
|
# File 'app/models/effective/form_logics/hide_if.rb', line 23
def logic_options
{ name: tag_name(args.first), value: args.second.to_s, needDisable: hide? }.merge(input_logic_options)
end
|
#options ⇒ Object
19
20
21
|
# File 'app/models/effective/form_logics/hide_if.rb', line 19
def options
{ style: ('display: none;' if hide?), class: 'effective-form-logic' }
end
|
#to_html(&block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/models/effective/form_logics/hide_if.rb', line 7
def to_html(&block)
disabled_was = @builder.disabled
@builder.disabled = true if hide?
content = content_tag(:div, options.merge(input_js_options), &block)
@builder.disabled = disabled_was
content
end
|
#validate!(args) ⇒ Object
31
32
33
34
|
# File 'app/models/effective/form_logics/hide_if.rb', line 31
def validate!(args)
return if args.third.kind_of?(Hash) && args.third[:validate] == false
raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
end
|