Sha256: 4a08cb59239e342c95752cd4b923a8402c6f045cdd146be8c16457fd15734981

Contents?: true

Size: 818 Bytes

Versions: 2

Compression:

Stored size: 818 Bytes

Contents

# frozen_string_literal: true

module DynamicScaffold
  module Form
    module Item
      class JSONObject < Base
        attr_reader :form
        def initialize(config, type, name, options = {})
          super
          @options = options
          @form = FormBuilder.new(config)
          @form.parent_item = self
          yield(@form)
        end

        # the lable is always empty.
        def render_label(_view, _depth)
          ''
        end

        def extract_parameters(permitting)
          hash = permitting.find {|e| e.is_a?(Hash) && e.key?(name) }
          if hash.nil?
            hash = {}
            hash[name] = form.items.map(&:name)
            permitting << hash
          else
            hash[name].concat(form.items.map(&:name))
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamic_scaffold-2.0.1 lib/dynamic_scaffold/form/item/json_object.rb
dynamic_scaffold-2.0.0 lib/dynamic_scaffold/form/item/json_object.rb