views: factor out search_form_for helper.
Refactor search forms to use `search_form_for` so that we can set common options on all search forms, such as autocomplete="off" (#4162).
This commit is contained in:
@@ -162,6 +162,13 @@ module ApplicationHelper
|
||||
tag.input value: "Preview", type: "button", class: "dtext-preview-button", "data-input-id": input_id, "data-preview-id": preview_id
|
||||
end
|
||||
|
||||
def search_form_for(url, classes: "inline-form", &block)
|
||||
defaults = { required: false }
|
||||
html_options = { autocomplete: "off", class: "search-form #{classes}" }
|
||||
|
||||
simple_form_for(:search, method: :get, url: url, defaults: defaults, html: html_options, &block)
|
||||
end
|
||||
|
||||
def search_field(method, label: method.titleize, hint: nil, value: nil, **attributes)
|
||||
content_tag(:div, class: "input") do
|
||||
label_html = label_tag("search_#{method}", label)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div id="a-search">
|
||||
<h1>Search Artist Commentary</h1>
|
||||
|
||||
<%= simple_form_for(:search, url: artist_commentaries_path, method: :get, defaults: { required: false }) do |f| %>
|
||||
<%= search_form_for(artist_commentaries_path) do |f| %>
|
||||
<%= f.input :text_matches, label: "Text" %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :original_present, label: "Original present?", collection: ["yes", "no"] %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div id="c-artist-urls">
|
||||
<div id="a-index">
|
||||
<%= simple_form_for(:search, url: artist_urls_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(artist_urls_path) do |f| %>
|
||||
<%= f.simple_fields_for :artist do |fa| %>
|
||||
<%= fa.input :name, label: "Artist Name", input_html: { value: params.dig(:search, :artist, :name), "data-autocomplete": "artist" } %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: artists_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(artists_path) do |f| %>
|
||||
<%= f.input :any_name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:any_name_matches], data: { autocomplete: "artist" }} %>
|
||||
<%= f.input :url_matches, label: "URL", as: "string", input_html: { value: params[:search][:url_matches] } %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, method: :get, url: bans_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(bans_path) do |f| %>
|
||||
<%= f.input :user_name, label: "User", input_html: { value: params[:search][:user_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :banner_name, label: "Banner", input_html: { value: params[:search][:banner_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :reason_matches, label: "Reason", hint: "Use * for wildcard", input_html: { value: params[:search][:reason_matches] } %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: bulk_update_requests_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(bulk_update_requests_path) do |f| %>
|
||||
<%= f.input :user_name, label: "Creator", input_html: { value: params[:search][:user_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :approver_name, label: "Approver", input_html: { value: params[:search][:approver_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :title_matches, label: "Title", input_html: { value: params[:search][:title_matches] } %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div id="a-search">
|
||||
<h1>Search Comments</h1>
|
||||
|
||||
<%= simple_form_for(:search, :method => :get, url: comments_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(comments_path) do |f| %>
|
||||
<%= hidden_field_tag "group_by", "comment", :id => "group_by_full" %>
|
||||
<%= f.input :creator_name, label: "Commenter", input_html: { data: { autocomplete: "user" } } %>
|
||||
<%= f.input :body_matches, label: "Body" %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: dmails_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(dmails_path) do |f| %>
|
||||
<%= f.hidden_field :folder, value: params[:folder] %>
|
||||
<%= f.input :title_matches, label: "Title", hint: "Use * for wildcard", input_html: { value: params[:search][:title_matches] } %>
|
||||
<%= f.input :message_matches, label: "Message", hint: "Use * for wildcard", input_html: { value: params[:search][:messages_matches] } %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, method: :get, url: mod_actions_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(mod_actions_path) do |f| %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :description_matches, label: "Description" %>
|
||||
<%= f.input :category, label: "Category", collection: ModAction.categories.map {|k,v| [k.capitalize.tr("_"," "), v]}, include_blank: true,selected: params[:search][:category] %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: moderator_dashboard_path, method: :get) do |f| %>
|
||||
<%= search_form_for(moderator_dashboard_path) do |f| %>
|
||||
<%= f.input :min_date, as: :date, html5: true, input_html: { value: @dashboard.min_date } %>
|
||||
<%= f.input :max_level, collection: User.level_hash.to_a, include_blank: true, selected: @dashboard.max_level %>
|
||||
<%= f.submit "Search" %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div id="a-index">
|
||||
<h1>Disapprovals</h1>
|
||||
|
||||
<%= simple_form_for(:search, url: moderator_post_disapprovals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(moderator_post_disapprovals_path) do |f| %>
|
||||
<%= f.input :user_name, label: "Creator", input_html: { value: params[:search][:user_name] } %>
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div id="a-search">
|
||||
<h1>Search Notes</h1>
|
||||
|
||||
<%= simple_form_for(:search, url: notes_path, method: :get, defaults: { required: false }) do |f| %>
|
||||
<%= search_form_for(notes_path) do |f| %>
|
||||
<%= f.hidden_field :group_by, value: "note" %>
|
||||
|
||||
<%= f.input :body_matches, label: "Body" %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: post_appeals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(post_appeals_path) do |f| %>
|
||||
<%= f.input :reason_matches, label: "Reason", hint: "Use * for wildcard searches", input_html: { value: params[:search][:reason_matches] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<h1>Approvals</h1>
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= simple_form_for(:search, url: post_approvals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(post_approvals_path) do |f| %>
|
||||
<%= f.input :user_name, label: "Approver", input_html: { value: params[:search][:user_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.submit "Search" %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: post_flags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(post_flags_path) do |f| %>
|
||||
<%= f.input :reason_matches, label: "Reason", hint: "Use * for wildcard searches", input_html: { value: params[:search][:reason_matches] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= simple_form_for(:search, url: post_replacements_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(post_replacements_path) do |f| %>
|
||||
<%= f.input :creator_name, label: "Replacer", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.submit "Search" %>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<% end %>
|
||||
</h1>
|
||||
|
||||
<%= simple_form_for(:search, url: saved_searches_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(saved_searches_path) do |f| %>
|
||||
<%= f.input :query_ilike, label: "Query", input_html: { value: params[:search][:query_ilike] } %>
|
||||
<%= f.input :label, label: "Label", input_html: { value: params[:search][:label] } %>
|
||||
<%= f.submit "Search" %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%# url %>
|
||||
|
||||
<%= simple_form_for(:search, method: :get, url: url, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(url) do |f| %>
|
||||
<%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
||||
<%= f.input :status, label: "Status", collection: %w[Approved Active Pending Deleted Retired Processing Queued], include_blank: true, selected: params[:search][:status] %>
|
||||
<%= f.simple_fields_for :antecedent_tag do |fa| %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: tags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(tags_path) do |f| %>
|
||||
<%= f.input :name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
||||
<%= f.input :category, label: "Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true,selected: params[:search][:category] %>
|
||||
<%= f.input :order, collection: [%w[Newest date], %w[Count count], %w[Name name]], include_blank: false, selected: params[:search][:order] %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for(:search, url: uploads_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(uploads_path) do |f| %>
|
||||
<%= f.input :uploader_name, label: "Uploader", input_html: { value: params[:search][:uploader_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :post_tags_match, label: "Post Tags", input_html: { value: params[:search][:post_tags_match] } %>
|
||||
<%= f.input :source_matches, label: "Source", input_html: { value: params[:search][:source_matches] } %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div id="c-users">
|
||||
<div id="a-search">
|
||||
<%= simple_form_for(:search, url: users_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= search_form_for(users_path) do |f| %>
|
||||
<%= f.input :name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:name_matches], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :inviter_name, label: "Inviter Name", hint: "Use * for wildcard", input_html: { value: params.dig(:search, :inviter_name), data: { autocomplete: "user" } } %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user