Sha256: 50b2162b2b92eda3ba712cf79e413e15469650c7c83aa710e2478af9b8980b0f

Contents?: true

Size: 1005 Bytes

Versions: 73

Compression:

Stored size: 1005 Bytes

Contents

module Effective
  module FormLogics
    class ShowIfAny < Effective::FormLogic

      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

      def options
        { style: ('display: none;' unless show?) }
      end

      def logic_options
        { name: tag_name(args.first), value: args.second.to_json, needDisable: !show? }.merge(input_logic_options)
      end

      def input_logic_options
        args.third.kind_of?(Hash) ? args.third : {}
      end

      def validate!(args)
        raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
      end

      def show?
        Array(args.second).any? do |value|
          selected = object.send(args.first)
          selected == value || selected.to_s == value.to_s
        end
      end

    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
effective_bootstrap-0.9.47 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.46 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.45 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.44 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.43 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.42 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.41 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.40 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.39 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.38 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.37 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.36 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.35 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.34 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.33 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.32 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.31 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.30 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.29 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.9.28 app/models/effective/form_logics/show_if_any.rb