Sha256: 0a9c136126c94fc043a4f03c2a768f2c27cbadb43e9bf179a249e7dee435ea2a

Contents?: true

Size: 1.01 KB

Versions: 23

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

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

23 entries across 23 versions & 1 rubygems

Version Path
effective_bootstrap-0.11.2 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.11.1 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.11.0 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.17 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.16 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.15 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.14 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.13 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.12 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.11 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.10 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.9 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.8 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.7 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.6 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.5 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.4 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.3 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.2 app/models/effective/form_logics/show_if_any.rb
effective_bootstrap-0.10.1 app/models/effective/form_logics/show_if_any.rb