Class: Effective::FormLogics::ShowIf

Inherits:
Effective::FormLogic show all
Defined in:
app/models/effective/form_logics/show_if.rb

Instance Attribute Summary

Attributes inherited from Effective::FormLogic

#args

Instance Method Summary collapse

Methods inherited from Effective::FormLogic

#initialize, #input_js_options, #input_js_options_method_name, #tag_name

Constructor Details

This class inherits a constructor from Effective::FormLogic

Instance Method Details

#input_logic_optionsObject



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_optionsObject



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

#optionsObject



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

Returns:

  • (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 = (: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