Sha256: f3c3202adf341c61d151c5287c73f594e4acb8e44ff5ed41d50ccb6629b8bb76

Contents?: true

Size: 914 Bytes

Versions: 8

Compression:

Stored size: 914 Bytes

Contents

module Effective
  module FormLogics
    class HideIf < Effective::FormLogic

      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

      def options
        { style: ('display: none;' if hide?) }
      end

      def logic_options
        { name: tag_name(args.first), value: args.second.to_s }.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 hide?
        (object.send(args.first) == args.second) || (object.send(args.first).to_s == args.second.to_s)
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
effective_bootstrap-0.6.14 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.13 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.12 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.11 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.10 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.9 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.8 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.6.7 app/models/effective/form_logics/hide_if.rb