Emi Matchu
1119bbb292
I think helpers are fine for the simpler ones that are basically *just* wrapper tags, but once it starts getting into `concat`, I think that's too unfamiliar of a syntax for developers; let's bail into our usual templating system! I'm not sure about putting them in `application/support_form` like this. That's cute for one-offs like `application/hanger_spinner`, because `render partial: "hanger_spinner"` assumes the `application` view folder by default, but that doesn't work once it's nested: it looks for a `views/support_form` folder. I think maybe it could soon be time to bail from the strict "view folders belong to controllers" thing, similar to how we did for `SupportFormHelper`, and add a `components` folder or similar? Idk, not sure yet!
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
module SupportFormHelper
|
|
class SupportFormBuilder < ActionView::Helpers::FormBuilder
|
|
attr_reader :template
|
|
delegate :capture, :content_tag, :render, to: :template, private: true
|
|
|
|
def errors
|
|
render partial: "application/support_form/errors", locals: {form: self}
|
|
end
|
|
|
|
def fields(&block)
|
|
content_tag(:ul, class: "fields", &block)
|
|
end
|
|
|
|
def field(**options, &block)
|
|
content_tag(:li, **options, &block)
|
|
end
|
|
|
|
def radio_fieldset(legend, **options, &block)
|
|
render partial: "application/support_form/radio_fieldset",
|
|
locals: {form: self, legend:, options:, content: capture(&block)}
|
|
end
|
|
|
|
def radio_field(**options, &block)
|
|
content_tag(:li) do
|
|
content_tag(:label, **options, &block)
|
|
end
|
|
end
|
|
|
|
def radio_grid_fieldset(*args, &block)
|
|
radio_fieldset(*args, "data-type": "radio-grid", &block)
|
|
end
|
|
|
|
def thumbnail_input(method)
|
|
render partial: "application/support_form/thumbnail_input",
|
|
locals: {form: self, method:}
|
|
end
|
|
end
|
|
|
|
def support_form_with(**options, &block)
|
|
options.merge!(
|
|
builder: SupportFormBuilder,
|
|
class: ["support-form", options[:class]],
|
|
)
|
|
form_with(**options, &block)
|
|
end
|
|
end
|