forked from e621ng/e621ng
[Tags] Convert "Hide empty?" to checkbox
Also added option for a default value and made checkbox inputs react to "truthy" for backwards compatability
This commit is contained in:
parent
7cd266d7bb
commit
ff5dc78cf4
@ -3,20 +3,20 @@ class SearchFormBuilder < SimpleForm::FormBuilder
|
||||
options[:input_html] ||= {}
|
||||
options[:input_html][:data] = {}
|
||||
options[:input_html][:data][:autocomplete] = options[:autocomplete] if options[:autocomplete]
|
||||
options = insert_value_from_search_params(attribute_name, options)
|
||||
options = insert_value(attribute_name, options)
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def insert_value_from_search_params(attribute_name, options)
|
||||
value = @options[:search_params][attribute_name]
|
||||
def insert_value(attribute_name, options)
|
||||
value = @options[:search_params][attribute_name] || options[:default]&.to_s
|
||||
return options if value.nil?
|
||||
|
||||
if options[:collection]
|
||||
options[:selected] = value
|
||||
elsif options[:as]&.to_sym == :boolean
|
||||
options[:input_html][:checked] = true if value == "1"
|
||||
options[:input_html][:checked] = true if value.truthy?
|
||||
else
|
||||
options[:input_html][:value] = value
|
||||
end
|
||||
|
@ -2,8 +2,8 @@
|
||||
<%= f.input :name_matches, label: "Name", hint: "Use * for wildcard", autocomplete: "tag" %>
|
||||
<%= f.input :category, label: "Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true %>
|
||||
<%= f.input :order, collection: [%w[Newest date], %w[Count count], %w[Name name]], include_blank: false %>
|
||||
<%= f.input :hide_empty, label: "Hide empty?", collection: %w[yes no] %>
|
||||
<%= f.input :has_wiki, label: "Has wiki?", collection: %w[yes no], include_blank: true %>
|
||||
<%= f.input :has_artist, label: "Has artist?", collection: %w[yes no], include_blank: true %>
|
||||
<%= f.input :hide_empty, label: "Hide empty?", as: :boolean, default: true %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user