Sha256: 7d8ed765a098a52e64e8e038bcd926d63c1acb02a5211a8d87cf0eb96d40332c

Contents?: true

Size: 857 Bytes

Versions: 50

Compression:

Stored size: 857 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 }
      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 hide?
        (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.5.7 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.6 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.5 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.4 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.3 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.2 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.1 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.5.0 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.8 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.7 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.6 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.5 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.4 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.3 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.2 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.1 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.4.0 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.3.22 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.3.21 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-0.3.20 app/models/effective/form_logics/hide_if.rb