Sha256: ff30e913318f9f40186cf353a314c0f9f51fa4aafc81d627d771e4ce7e169b67

Contents?: true

Size: 1.19 KB

Versions: 919

Compression:

Stored size: 1.19 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, **kwargs, &block)
      data = data.merge("pb-form-validation" => validate)
      classname = ["pb-form", kwargs[:class]].join(" ")
      options = kwargs.merge(
        class: classname,
        data: data,
        builder: ::Playbook::Forms::Builder
      )

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

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

Version data entries

919 entries across 919 versions & 1 rubygems

Version Path
playbook_ui-14.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4175 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.20 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4162 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PBNTR595popoverwidthpropfilterpopoverprop4158 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PBNTR614advancedtablepoc4155 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.19 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.18 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.play1549upgradereactmodal4130 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1601updatereactzoompanpinch4128 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1601updatereactzoompanpinch4123 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.17 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.play1586datearea4115 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.16 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4098 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4097 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4094 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.15 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4077 lib/playbook/pb_forms_helper.rb
playbook_ui-14.6.0.pre.rc.14 lib/playbook/pb_forms_helper.rb
playbook_ui-14.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4073 lib/playbook/pb_forms_helper.rb