Emi Matchu
8347633a84
Instead of hand-rolling HTML, this offers helpers like `f.field`, to help ensure the HTML is consistent, and to keep the templates more focused on the unique form elements.
42 lines
973 B
Ruby
42 lines
973 B
Ruby
module SupportFormHelper
|
|
class SupportFormBuilder < ActionView::Helpers::FormBuilder
|
|
attr_reader :template
|
|
delegate :concat, :content_tag, to: :template, private: true
|
|
|
|
def fields(&block)
|
|
content_tag(:ul, class: "fields", &block)
|
|
end
|
|
|
|
def field(**kwargs, &block)
|
|
content_tag(:li, **kwargs, &block)
|
|
end
|
|
|
|
def radio_fieldset(legend, **kwargs, &block)
|
|
kwargs.reverse_merge!("data-type": "radio")
|
|
field(**kwargs) do
|
|
content_tag(:fieldset) do
|
|
concat content_tag(:legend, legend)
|
|
concat content_tag(:ul, &block)
|
|
end
|
|
end
|
|
end
|
|
|
|
def radio_field(**kwargs, &block)
|
|
content_tag(:li) do
|
|
content_tag(:label, **kwargs, &block)
|
|
end
|
|
end
|
|
|
|
def radio_grid_fieldset(*args, &block)
|
|
radio_fieldset(*args, "data-type": "radio-grid", &block)
|
|
end
|
|
end
|
|
|
|
def support_form_with(**kwargs, &block)
|
|
kwargs.merge!(
|
|
builder: SupportFormBuilder,
|
|
class: ["support-form", kwargs[:class]],
|
|
)
|
|
form_with(**kwargs, &block)
|
|
end
|
|
end
|