mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-31 11:21:06 -04:00
37 lines
1.8 KiB
Plaintext
37 lines
1.8 KiB
Plaintext
-# A field is usually one attribute, but may be a pair edited together — a min
|
|
-# and a max. The first of the pair names the form.
|
|
- fields = Array(field)
|
|
- form_id = editable_form_id(model, field)
|
|
- what = fields.one? ? fields.first.to_s : fields.first.to_s.sub(/_(min|max)\z/, '')
|
|
- trigger = local_assigns.fetch(:trigger, :pencil)
|
|
- if can? :edit, model
|
|
- if trigger == :pencil
|
|
%small.edit-link
|
|
%a.editable{ "data-form" => "##{form_id}", "data-display": display_field, href: "#", name: "##{form_id}" }
|
|
-# One muted pencil everywhere, not the orange SVG icon.
|
|
= menu_icon(:edit)
|
|
%span.visually-hidden Edit #{what.humanize.downcase}
|
|
|
|
-# The fact card's own h3 already names the field, so the generated label
|
|
-# would print it a second time right under it. hide_label keeps the label
|
|
-# in the markup for screen readers and takes it off the screen. A pair is
|
|
-# the exception: "min" and "max" tell the two apart and the h3 says neither.
|
|
.hide{ id: form_id }
|
|
= bootstrap_form_for(model) do |f|
|
|
- if field_type == :text_area
|
|
= f.text_area field, hide_label: true, rows: 4
|
|
- elsif field_type == :text_field
|
|
= f.text_field field, hide_label: true
|
|
- elsif field_type == :select
|
|
= f.select field, values, hide_label: true
|
|
- elsif field_type == :number_field
|
|
= f.number_field field, hide_label: true, min: values&.first, max: values&.last
|
|
- elsif field_type == :number_range
|
|
.row.g-2
|
|
.col-6= f.number_field fields.first, label: 'min', min: 0
|
|
.col-6= f.number_field fields.last, label: 'max', min: 0
|
|
- elsif field_type == :date
|
|
= f.date_field field,
|
|
value: model.send(field) ? model.send(field).to_fs(:ymd) : '', label: 'When?'
|
|
= f.submit :save
|