Sha256: dc5a3cd5fe9ab0ae4648b343e01990257793c2efe8958db6bf4c445cd48a4b2f

Contents?: true

Size: 1.48 KB

Versions: 22

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

if defined?(SimpleForm)
module Playbook
  module PbForm
    class SimpleForm < Playbook::KitBase
      class FormBuilder < ::SimpleForm::FormBuilder
        include ::Playbook::PbForm::FormBuilder

        def input(attribute_name, options = {}, &block)
          super(
            attribute_name,
            options.deep_merge(label: false, input_html: {
                            props: {
                              label: true,
                            },
                          }),
            &block
          )
        end
      end

      prop :options, type: Playbook::Props::Hash, default: {}
      prop :validate, type: Playbook::Props::Boolean, default: false

      def options
        {
          builder: Playbook::PbForm::SimpleForm::FormBuilder,
          html: html_options,
          data: data,
          url: "",
        }.merge(prop(:options))
      end

      def model
        prop(:options).fetch(:model, nil)
      end

      def data
        prop(:data).merge("pb-form-validation" => validate)
      end

      def classname
        [generate_classname("pb-form"), html[:class]].join(" ")
      end

      def html
        prop(:options).fetch(:html, {})
      end

      def render_form(builder)
        view_context.capture(builder, &children)
      end

      def render_in(view_context, &_block)
        super(view_context, &nil)
      end

    private

      def html_options
        html.merge(class: classname)
      end
    end
  end
end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
playbook_ui-8.3.0.alpha.select.pre.margin app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.3.0 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1.pre.alpha5 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1.pre.alpha4 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1.alpha.iconacc app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1.pre.alpha3 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1.pre.alpha2 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.3.0.deps2 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.3.0.pre.alpha1 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1.pre.alpha1 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.1 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.1.3 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.4.0.alpha.dependencies.2 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.4.0.alpha.dependencies.1 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.0.pre.alpha4 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.0.pre.alpha3 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.2.0 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.1.2 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.1.0.pre.alpha1 app/pb_kits/playbook/pb_form/simple_form.rb
playbook_ui-8.0.3 app/pb_kits/playbook/pb_form/simple_form.rb