Form uses button instead of input to display SVG

This commit is contained in:
2024-12-23 00:47:44 +01:00
parent 8f85432982
commit a9307ad455
6 changed files with 20 additions and 3 deletions

View File

@@ -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"