Sha256: 7094df279c5d9d41199305f3216bd30e6d4d1f52d69d264f2d3e18694f3bb5fd

Contents?: true

Size: 865 Bytes

Versions: 50

Compression:

Stored size: 865 Bytes

Contents

module Effective
  module FormLogics
    class ShowIf < 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_s }
      end

      def validate!(args)
        raise 'expected two arguments' unless args.length == 2
        raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
      end

      def show?
        (object.send(args.first) == args.second) || (object.send(args.first).to_s == args.second.to_s)
      end

    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
effective_bootstrap-0.6.6 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.6.5 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.6.4 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.6.3 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.6.2 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.6.1 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.6.0 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.20 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.19 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.18 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.17 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.16 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.15 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.14 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.13 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.12 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.11 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.10 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.9 app/models/effective/form_logics/show_if.rb
effective_bootstrap-0.5.8 app/models/effective/form_logics/show_if.rb