forked from fixin.me/fixin.me
Form uses button instead of input to display SVG
This commit is contained in:
parent
8f85432982
commit
a9307ad455
1
app/assets/images/pictograms/plus-circle-outline.svg
Normal file
1
app/assets/images/pictograms/plus-circle-outline.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" id="icon" viewBox="0 0 24 24"><path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M13,7H11V11H7V13H11V17H13V13H17V11H13V7Z" /></svg>
|
After Width: | Height: | Size: 297 B |
1
app/assets/images/pictograms/update.svg
Normal file
1
app/assets/images/pictograms/update.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" id="icon" viewBox="0 0 24 24"><path d="M21,10.12H14.22L16.96,7.3C14.23,4.6 9.81,4.5 7.08,7.2C4.35,9.91 4.35,14.28 7.08,17C9.81,19.7 14.23,19.7 16.96,17C18.32,15.65 19,14.08 19,12.1H21C21,14.08 20.12,16.65 18.36,18.39C14.85,21.87 9.15,21.87 5.64,18.39C2.14,14.92 2.11,9.28 5.62,5.81C9.13,2.34 14.76,2.34 18.27,5.81L21,3V10.12M12.5,8V12.25L16,14.33L15.28,15.54L11,13V8H12.5Z" /></svg>
|
After Width: | Height: | Size: 423 B |
@ -55,11 +55,26 @@ module ApplicationHelper
|
||||
form_for(record, **options) { |f| f.form_for(&block) }
|
||||
end
|
||||
|
||||
class TabularFormBuilder < ActionView::Helpers::FormBuilder
|
||||
private
|
||||
|
||||
def submit_default_value
|
||||
svg_name = object ? (object.persisted? ? 'update' : 'plus-circle-outline') : ''
|
||||
@template.svg_tag("pictograms/#{svg_name}") + super
|
||||
end
|
||||
end
|
||||
|
||||
def tabular_fields_for(record_name, record_object = nil, options = {}, &block)
|
||||
options.merge! builder: TabularFormBuilder
|
||||
render_errors(record_name)
|
||||
fields_for(record_name, record_object, **options, &block)
|
||||
end
|
||||
|
||||
def tabular_form_with(**options, &block)
|
||||
options.merge! builder: TabularFormBuilder
|
||||
form_with(**options, &block)
|
||||
end
|
||||
|
||||
def svg_tag(source, options = {})
|
||||
content_tag :svg, options do
|
||||
tag.use href: image_path(source + ".svg") + "#icon"
|
||||
|
@ -20,7 +20,7 @@
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
<%= form.submit form: form_tag %>
|
||||
<%= form.button form: form_tag %>
|
||||
<%= image_link_to t(:cancel), "close-outline", units_path, class: 'dangerous',
|
||||
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
||||
</td>
|
||||
|
@ -4,7 +4,7 @@
|
||||
form_tag: dom_id(@unit, :edit, :form)} %>
|
||||
|
||||
<%= turbo_stream.append :unit_form do %>
|
||||
<%- form_with model: @unit, html: {id: ids[:form_tag]} do %>
|
||||
<%- tabular_form_with model: @unit, html: {id: ids[:form_tag]} do %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<%= turbo_stream.disable ids[:link] -%>
|
||||
|
||||
<%= turbo_stream.append :unit_form do %>
|
||||
<%- form_with model: @unit, html: {id: ids[:form_tag]} do %>
|
||||
<%- tabular_form_with model: @unit, html: {id: ids[:form_tag]} do %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user