Extract alt style's "go to next" field into a support form helper
I want to reuse this for unlabeled pet styles is why! (That's been the immediate motivation for this refactor, but also I do just like that it'll make support forms easier to build.)
This commit is contained in:
parent
06a301e6d7
commit
aeb00f73cf
3 changed files with 18 additions and 10 deletions
|
@ -89,9 +89,9 @@
|
||||||
align-items: center
|
align-items: center
|
||||||
gap: 1em
|
gap: 1em
|
||||||
|
|
||||||
label
|
.go-to-next
|
||||||
display: flex
|
display: flex
|
||||||
align-items: center
|
align-items: center
|
||||||
gap: .25em
|
gap: .25em
|
||||||
font-size: .85em
|
font-size: .85em
|
||||||
font-style: italic
|
font-style: italic
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
module SupportFormHelper
|
module SupportFormHelper
|
||||||
class SupportFormBuilder < ActionView::Helpers::FormBuilder
|
class SupportFormBuilder < ActionView::Helpers::FormBuilder
|
||||||
attr_reader :template
|
attr_reader :template
|
||||||
delegate :capture, :content_tag, :render, to: :template, private: true
|
delegate :capture, :check_box_tag, :content_tag, :params, :render,
|
||||||
|
to: :template, private: true
|
||||||
|
|
||||||
def errors
|
def errors
|
||||||
render partial: "application/support_form/errors", locals: {form: self}
|
render partial: "application/support_form/errors", locals: {form: self}
|
||||||
|
@ -38,6 +39,14 @@ module SupportFormHelper
|
||||||
def actions(&block)
|
def actions(&block)
|
||||||
content_tag(:section, class: "actions", &block)
|
content_tag(:section, class: "actions", &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def go_to_next_field(**options, &block)
|
||||||
|
content_tag(:label, class: "go-to-next", **options, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def go_to_next_check_box(value)
|
||||||
|
check_box_tag "next", value, checked: params[:next] == value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def support_form_with(**options, &block)
|
def support_form_with(**options, &block)
|
||||||
|
|
|
@ -28,9 +28,8 @@
|
||||||
|
|
||||||
= f.actions do
|
= f.actions do
|
||||||
= f.submit "Save changes"
|
= f.submit "Save changes"
|
||||||
%label{title: "If checked, takes you to the next unlabeled pet style, if any. Useful for labeling in bulk!"}
|
= f.go_to_next_field title: "If checked, takes you to the next unlabeled pet style, if any. Useful for labeling in bulk!" do
|
||||||
= check_box_tag "next", "unlabeled-style",
|
= f.go_to_next_check_box "unlabeled-style"
|
||||||
checked: params[:next] == "unlabeled-style"
|
|
||||||
Then: Go to unlabeled style
|
Then: Go to unlabeled style
|
||||||
|
|
||||||
- content_for :stylesheets do
|
- content_for :stylesheets do
|
||||||
|
|
Loading…
Reference in a new issue