2024-11-30 11:26:23 -08:00
|
|
|
module SupportFormHelper
|
|
|
|
class SupportFormBuilder < ActionView::Helpers::FormBuilder
|
|
|
|
attr_reader :template
|
2024-12-08 10:08:39 -08:00
|
|
|
delegate :capture, :check_box_tag, :concat, :content_tag,
|
|
|
|
:hidden_field_tag, :params, :render,
|
2024-12-01 09:42:19 -08:00
|
|
|
to: :template, private: true
|
2024-11-30 11:26:23 -08:00
|
|
|
|
2024-11-30 11:46:19 -08:00
|
|
|
def errors
|
2024-12-01 09:26:40 -08:00
|
|
|
render partial: "application/support_form/errors", locals: {form: self}
|
2024-11-30 11:46:19 -08:00
|
|
|
end
|
|
|
|
|
2024-11-30 11:26:23 -08:00
|
|
|
def fields(&block)
|
|
|
|
content_tag(:ul, class: "fields", &block)
|
|
|
|
end
|
|
|
|
|
2024-12-01 09:26:40 -08:00
|
|
|
def field(**options, &block)
|
|
|
|
content_tag(:li, **options, &block)
|
2024-11-30 11:26:23 -08:00
|
|
|
end
|
|
|
|
|
2024-12-01 09:26:40 -08:00
|
|
|
def radio_fieldset(legend, **options, &block)
|
|
|
|
render partial: "application/support_form/radio_fieldset",
|
|
|
|
locals: {form: self, legend:, options:, content: capture(&block)}
|
2024-11-30 11:26:23 -08:00
|
|
|
end
|
|
|
|
|
2024-12-01 09:26:40 -08:00
|
|
|
def radio_field(**options, &block)
|
2024-11-30 11:26:23 -08:00
|
|
|
content_tag(:li) do
|
2024-12-01 09:26:40 -08:00
|
|
|
content_tag(:label, **options, &block)
|
2024-11-30 11:26:23 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def radio_grid_fieldset(*args, &block)
|
|
|
|
radio_fieldset(*args, "data-type": "radio-grid", &block)
|
|
|
|
end
|
2024-11-30 11:34:02 -08:00
|
|
|
|
|
|
|
def thumbnail_input(method)
|
2024-12-01 09:26:40 -08:00
|
|
|
render partial: "application/support_form/thumbnail_input",
|
|
|
|
locals: {form: self, method:}
|
2024-11-30 11:34:02 -08:00
|
|
|
end
|
2024-12-01 09:30:17 -08:00
|
|
|
|
|
|
|
def actions(&block)
|
|
|
|
content_tag(:section, class: "actions", &block)
|
|
|
|
end
|
2024-12-01 09:42:19 -08:00
|
|
|
|
2024-12-08 10:08:39 -08:00
|
|
|
def go_to_next_field(after: nil, **options, &block)
|
|
|
|
content_tag(:label, class: "go-to-next", **options) do
|
|
|
|
concat hidden_field_tag(:after, after) if after
|
|
|
|
yield
|
|
|
|
end
|
2024-12-01 09:42:19 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def go_to_next_check_box(value)
|
|
|
|
check_box_tag "next", value, checked: params[:next] == value
|
|
|
|
end
|
2024-11-30 11:26:23 -08:00
|
|
|
end
|
|
|
|
|
2024-12-01 09:26:40 -08:00
|
|
|
def support_form_with(**options, &block)
|
2024-12-01 09:45:26 -08:00
|
|
|
form_with(
|
2024-11-30 11:26:23 -08:00
|
|
|
builder: SupportFormBuilder,
|
2024-12-01 09:45:26 -08:00
|
|
|
**options,
|
2024-12-01 09:26:40 -08:00
|
|
|
class: ["support-form", options[:class]],
|
2024-12-01 09:45:26 -08:00
|
|
|
&block
|
2024-11-30 11:26:23 -08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|