Sha256: 651462b61b683e65dd134e29a6d855daa5b4c631583360582aa97fe45873de29

Contents?: true

Size: 1.02 KB

Versions: 78

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

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, needDisable: hide? }.merge(input_logic_options)
      end

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

      def validate!(args)
        return if args.third.kind_of?(Hash) && args.third[:validate] == false
        raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
      end

      def hide?
        (object.try(args.first) == args.second) || (object.try(args.first).to_s == args.second.to_s)
      end

    end
  end
end

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
effective_bootstrap-1.18.4 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.18.3 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.18.2 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.18.1 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.18.0 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.6 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.5 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.4 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.3 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.2 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.1 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.17.0 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.16.4 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.16.3 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.16.2 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.16.1 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.16.0 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.15.6 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.15.5 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.15.4 app/models/effective/form_logics/hide_if.rb