Add thumbnail_input method to support form builder

Just to clean up this relatively common input type!
This commit is contained in:
Emi Matchu 2024-11-30 11:34:02 -08:00
parent 8347633a84
commit 3cd02baa09
3 changed files with 11 additions and 9 deletions

View file

@ -1,7 +1,7 @@
module SupportFormHelper module SupportFormHelper
class SupportFormBuilder < ActionView::Helpers::FormBuilder class SupportFormBuilder < ActionView::Helpers::FormBuilder
attr_reader :template attr_reader :template
delegate :concat, :content_tag, to: :template, private: true delegate :concat, :content_tag, :image_tag, to: :template, private: true
def fields(&block) def fields(&block)
content_tag(:ul, class: "fields", &block) content_tag(:ul, class: "fields", &block)
@ -30,6 +30,14 @@ module SupportFormHelper
def radio_grid_fieldset(*args, &block) def radio_grid_fieldset(*args, &block)
radio_fieldset(*args, "data-type": "radio-grid", &block) radio_fieldset(*args, "data-type": "radio-grid", &block)
end end
def thumbnail_input(method)
url = object.send(method)
content_tag(:div, class: "thumbnail-input") do
concat image_tag(url, alt: "Thumbnail") if url.present?
concat url_field(method)
end
end
end end
def support_form_with(**kwargs, &block) def support_form_with(**kwargs, &block)

View file

@ -29,10 +29,7 @@
= f.field do = f.field do
= f.label :thumbnail_url, "Thumbnail" = f.label :thumbnail_url, "Thumbnail"
.thumbnail-input = f.thumbnail_input :thumbnail_url
- if @alt_style.thumbnail_url?
= image_tag @alt_style.thumbnail_url
= f.url_field :thumbnail_url
.actions .actions
= f.submit "Save changes" = f.submit "Save changes"

View file

@ -23,10 +23,7 @@
= f.field do = f.field do
= f.label :thumbnail_url, "Thumbnail" = f.label :thumbnail_url, "Thumbnail"
.thumbnail-input = f.thumbnail_input :thumbnail_url
- if @item.thumbnail_url?
= image_tag @item.thumbnail_url
= f.url_field :thumbnail_url
= f.field do = f.field do
= f.label :description = f.label :description