Skip to content

Adding a range limit to the advanced search form

Jonathan Rochkind edited this page Mar 5, 2014 · 3 revisions

If you use blacklight_range_limit to have a range search limit, you may want to add an input for that limit, as a range, to the advanced search form.

Here's one way to do it, a bit hacky, but it works. (Written for blacklight_advanced_search 5.0).

Over-ride the advanced_search_form partial, by creating a file in your local app at views/advanced/_advanced_search_form.html.erb. Copy the contents of blacklight_advanced_search's equivalent file.

Now, decide where you want to add your new input: Probably either right after the advanced_search_fields or right after the advanced_search_facets. Wherever that is, add this code:

<div class="form-group advanced-search-facet">
  <%= label_tag "publication_date", :class => "col-sm-3 control-label" do %>
      Publication Year
  <% end %>

  <div class="col-sm-9">
      <%= render_range_input("pub_date_sort", :begin) %> - <%= render_range_input("pub_date_sort", :end) %>      
  </div>
</div>

pub_date_sort is an example of a name of a solr field we've applied range limit to. The render_range_input method used there is actually provided by blacklight_range_limit, and will render appropriate html inputs.

One downside of this technique is, since you've copied code from the original blacklight_advanced_search template, if the advanced search gem changes, you'll have to merge those changes, or re-copy and customize. Just a trade-off that comes with customization.

Clone this wiki locally