Module: Ariadne::ActionViewExtensions::FormHelper

Includes:
ClassNameHelper
Included in:
Component
Defined in:
app/lib/ariadne/action_view_extensions/form_helper.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_FORM_CLASSES =
"ariadne-space-y-8 sm:ariadne-space-y-5"

Instance Method Summary collapse

Methods included from ClassNameHelper

#class_names

Instance Method Details

#ariadne_form_with(model: nil, scope: nil, url: nil, format: nil, classes: "", attributes: {}, **options, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/lib/ariadne/action_view_extensions/form_helper.rb', line 10

def ariadne_form_with(model: nil, scope: nil, url: nil, format: nil, classes: "", attributes: {}, **options, &block)
  options[:class] = class_names(DEFAULT_FORM_CLASSES, options[:class])
  options[:builder] ||= Ariadne::FormBuilder
  options[:html] ||= {}

  data = options.delete(:data) || {}
  attributes = attributes.delete_if do |key, value|
    key_name = key.to_s
    if key_name.start_with?("data-")
      data[key_name.sub(/^data-/, "").to_sym] = value
      true
    else
      false
    end
  end

  data[:controller] = if data.fetch(:controller, {}).present?
    "#{data[:controller]} ariadne-form"
  else
    "ariadne-form"
  end

  form_with(model: model, scope: scope, url: url, format: format, data: data, attributes: attributes, **options, &block)
end