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])
end
def search_field(method, options = {})
name = options[:label] || method.titleize
string = '<div class="input"><label for="search_' + method + '">' + name + '</label><input type="text" name="search[' + method + ']" id="search_' + method + '">'
if options[:hint]
string += '<p class="hint">' + options[:hint] + '</p>'
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)
input_html = text_field_tag(method, value, id: "search_#{method}", name: "search[#{method}]", **attributes)
hint_html = hint.present? ? content_tag(:p, hint, class: "hint") : ""
label_html + input_html + hint_html
end
string += '</div>'
string.html_safe
end
def body_attributes(user = CurrentUser.user)