Sha256: 892a9c7b258f84f5e60be63d0fa99a2ade6122db755cda3fa4b617024cd15b93

Contents?: true

Size: 1.32 KB

Versions: 98

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbFormsHelper
    # Renders a pb form with ::Playbook::Forms::Builder, that can render
    # Playbook kits in the most railsie way.
    #
    # I.e.:
    #
    #   pb_form_with model: @user do |f|
    #     f.text_field :name
    #   end
    #
    # The form can also validate the fields, and trigger the validation automatically:
    #
    # I.e.:
    #
    #   pb_form_with model: @user, validate: true do |f|
    #     f.text_field :name, required: true
    #   end
    #
    # @param data [Hash] hash of data attributes
    # @param validate [Boolean] whether validation should be triggered or not
    # @see [#form_with] for other options
    def pb_form_with(data: {}, validate: false, loading: false, **kwargs, &block)
      data = data.merge("pb-form-validation" => validate)
      classname = ["pb-form", kwargs[:class]].join(" ")
      classname += " pb_form_loading" if loading
      options = kwargs.merge(
        class: classname,
        data: data,
        builder: ::Playbook::Forms::Builder
      )

      content_for(:pb_js, javascript_tag(<<~JS))
        window.addEventListener("DOMContentLoaded", function() { PbFormValidation.start() })
        window.addEventListener("DOMContentLoaded", () => formHelper())
      JS

      form_with(**options, &block)
    end
  end
end

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4312 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4305 lib/playbook/pb_forms_helper.rb
playbook_ui-14.7.0.pre.rc.6 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4304 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4303 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4296 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1550lazysizesupgrade4295 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4274 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1607dependencydisplayymlupdate4271 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4262 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4260 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1550lazysizesupgrade4257 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4254 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4251 lib/playbook/pb_forms_helper.rb
playbook_ui-14.7.0.pre.rc.5 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4247 lib/playbook/pb_forms_helper.rb
playbook_ui-14.7.0.pre.rc.4 lib/playbook/pb_forms_helper.rb
playbook_ui-14.7.0.pre.rc.3 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.2 lib/playbook/pb_forms_helper.rb
playbook_ui-14.7.0.pre.rc.2 lib/playbook/pb_forms_helper.rb