Sha256: 43a19f9cbe8a82794b2d735b1448ac465d92a3a68734a03bad3d8cae59b4c67d
Contents?: true
Size: 1.12 KB
Versions: 15
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true module Effective module FormLogics class ShowIfAny < 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?), class: 'effective-form-logic' } end def logic_options { name: tag_name(args.first), value: args.second.to_json, needDisable: !show? }.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 show? Array(args.second).any? do |value| selected = object.try(args.first) selected == value || selected.to_s == value.to_s end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems