ApplicationHelper#search_field: accept html attributes on <input> field.

Rewrite `search_field` to allow setting `data-*` attributes on the <input> field.
This commit is contained in:
evazion
2018-02-18 16:09:17 -06:00
parent 26b260f1c8
commit a058a77c07

View File

@@ -163,14 +163,14 @@ module ApplicationHelper
submit_tag("Preview", "data-input-id" => options[:input_id], "data-preview-id" => options[:preview_id]) submit_tag("Preview", "data-input-id" => options[:input_id], "data-preview-id" => options[:preview_id])
end end
def search_field(method, options = {}) def search_field(method, label: method.titleize, hint: nil, value: nil, **attributes)
name = options[:label] || method.titleize content_tag(:div, class: "input") do
string = '<div class="input"><label for="search_' + method + '">' + name + '</label><input type="text" name="search[' + method + ']" id="search_' + method + '">' label_html = label_tag("search_#{method}", label)
if options[:hint] input_html = text_field_tag(method, value, id: "search_#{method}", name: "search[#{method}]", **attributes)
string += '<p class="hint">' + options[:hint] + '</p>' hint_html = hint.present? ? content_tag(:p, hint, class: "hint") : ""
label_html + input_html + hint_html
end end
string += '</div>'
string.html_safe
end end
def body_attributes(user = CurrentUser.user) def body_attributes(user = CurrentUser.user)