Sha256: 00c9f618ba7005f14f3365a51e1dd2791890d5523a3f455323fccc3064f9fa34

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 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?), class: 'effective-form-logic' }
      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

12 entries across 12 versions & 1 rubygems

Version Path
effective_bootstrap-1.19.10 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.9 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.8 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.7 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.6 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.5 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.4 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.3 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.2 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.1 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.19.0 app/models/effective/form_logics/hide_if.rb
effective_bootstrap-1.18.7 app/models/effective/form_logics/hide_if.rb