module Playbook::PbFormsHelper

def pb_form_with(data: {}, validate: false, **kwargs, &block)

Other tags:
    See: [#form_with] - for other options

Parameters:
  • validate (Boolean) -- whether validation should be triggered or not
  • data (Hash) -- hash of data attributes
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