Class: Effective::FormLogics::ShowIf
Instance Attribute Summary
#args
Instance Method Summary
collapse
#initialize, #input_js_options, #input_js_options_method_name, #tag_name
Instance Method Details
27
28
29
|
# File 'app/models/effective/form_logics/show_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/show_if.rb', line 23
def logic_options
{ name: tag_name(args.first), value: args.second.to_s, needDisable: !show? }.merge(input_logic_options)
end
|
#options ⇒ Object
19
20
21
|
# File 'app/models/effective/form_logics/show_if.rb', line 19
def options
{ style: ('display: none;' unless show?), class: 'effective-form-logic' }
end
|
#show? ⇒ Boolean
36
37
38
|
# File 'app/models/effective/form_logics/show_if.rb', line 36
def show?
(object.try(args.first) == args.second) || (object.try(args.first).to_s == args.second.to_s)
end
|
#to_html(&block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/models/effective/form_logics/show_if.rb', line 7
def to_html(&block)
disabled_was = @builder.disabled
@builder.disabled = true unless show?
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/show_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
|