Sha256: 625b45724210557c6e695131b184800f7a8751134e217d415a93c1d7af61da45

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Playbook
  module Forms
    class Builder
      class FormFieldBuilder < Module
        def initialize(method_name, kit_name:)
          define_method method_name do |name, props: {}, **options, &block|
            props[:label] = @template.label(@object_name, name) if props[:label] == true
            options = Hash(options)

            options[:skip_default_ids] = false unless options.key?(:skip_default_ids)
            options[:required] = true if props[:required]
            options[:placeholder] = props[:placeholder] || ""

            if props.key?(:validation)
              validation = props[:validation]
              options[:pattern] = validation[:pattern] if validation[:pattern].present?
              options[:data] = { message: validation[:message] } if validation[:message].present?
            end

            input = super(name, **options, &block)

            @template.pb_rails(kit_name, props:) do
              input
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
playbook_ui-13.21.0.pre.alpha.PLAY12582516 lib/playbook/forms/builder/form_field_builder.rb
playbook_ui-13.21.0.pre.alpha.PLAY12582515 lib/playbook/forms/builder/form_field_builder.rb
playbook_ui-13.21.0.pre.alpha.PLAY12582514 lib/playbook/forms/builder/form_field_builder.rb