[Search] Automatically add id/created_at/updated_at inputs

This won't be correct in some cases but the large majority will make sense
This commit is contained in:
Earlopain 2023-05-07 13:26:20 +02:00
parent 8e7914aad8
commit 83ad5f34ac
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
2 changed files with 7 additions and 3 deletions

View File

@ -11,7 +11,10 @@ module FormSearchHelper
defaults: { required: false },
html: { class: "inline-form" },
}) do |f|
capture { yield(f) } + f.submit("Search")
id_input = f.input(:id, label: "ID", hide_unless_value: true)
created_at_input = f.input(:created_at, hide_unless_value: true)
updated_at_input = f.input(:updated_at, hide_unless_value: true)
id_input + created_at_input + updated_at_input + capture { yield(f) } + f.submit("Search")
end
render "application/form_search", hideable: hideable, show_on_load: show_on_load, form: form
end
@ -22,6 +25,7 @@ module FormSearchHelper
def filled_form_fields(&)
form_field_collector = FormFieldCollector.new
capture { yield(form_field_collector) }
form_field_collector.fields & params[:search].keys.map(&:to_sym)
available_fields = %i[id created_at updated_at] + form_field_collector.fields
available_fields & params[:search].keys.map(&:to_sym)
end
end

View File

@ -1,7 +1,7 @@
class SearchFormBuilder < SimpleForm::FormBuilder
def input(attribute_name, options = {}, &)
value = value_for_attribute(attribute_name, options)
return if value.nil? && options[:hide_unless_value]
return "".html_safe if value.nil? && options[:hide_unless_value]
options = insert_autocomplete(options)
options = insert_value(value, options)
super