Add thumbnail_input
method to support form builder
Just to clean up this relatively common input type!
This commit is contained in:
parent
8347633a84
commit
3cd02baa09
3 changed files with 11 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
module SupportFormHelper
|
||||
class SupportFormBuilder < ActionView::Helpers::FormBuilder
|
||||
attr_reader :template
|
||||
delegate :concat, :content_tag, to: :template, private: true
|
||||
delegate :concat, :content_tag, :image_tag, to: :template, private: true
|
||||
|
||||
def fields(&block)
|
||||
content_tag(:ul, class: "fields", &block)
|
||||
|
@ -30,6 +30,14 @@ module SupportFormHelper
|
|||
def radio_grid_fieldset(*args, &block)
|
||||
radio_fieldset(*args, "data-type": "radio-grid", &block)
|
||||
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
|
||||
|
||||
def support_form_with(**kwargs, &block)
|
||||
|
|
|
@ -29,10 +29,7 @@
|
|||
|
||||
= f.field do
|
||||
= f.label :thumbnail_url, "Thumbnail"
|
||||
.thumbnail-input
|
||||
- if @alt_style.thumbnail_url?
|
||||
= image_tag @alt_style.thumbnail_url
|
||||
= f.url_field :thumbnail_url
|
||||
= f.thumbnail_input :thumbnail_url
|
||||
|
||||
.actions
|
||||
= f.submit "Save changes"
|
||||
|
|
|
@ -23,10 +23,7 @@
|
|||
|
||||
= f.field do
|
||||
= f.label :thumbnail_url, "Thumbnail"
|
||||
.thumbnail-input
|
||||
- if @item.thumbnail_url?
|
||||
= image_tag @item.thumbnail_url
|
||||
= f.url_field :thumbnail_url
|
||||
= f.thumbnail_input :thumbnail_url
|
||||
|
||||
= f.field do
|
||||
= f.label :description
|
||||
|
|
Loading…
Reference in a new issue