Class: Blacklight::SearchBarComponent
- Defined in:
- app/components/blacklight/search_bar_component.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Component
Instance Method Summary collapse
- #advanced_search_enabled? ⇒ Boolean
-
#autocomplete_path ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #autofocus ⇒ Object
-
#initialize(url:, params:, advanced_search_url: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }, form_options: {}) ⇒ SearchBarComponent
constructor
rubocop:disable Metrics/ParameterLists.
- #search_fields ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(url:, params:, advanced_search_url: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }, form_options: {}) ⇒ SearchBarComponent
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/components/blacklight/search_bar_component.rb', line 11 def initialize( url:, params:, advanced_search_url: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }, form_options: {} ) @url = url @advanced_search_url = advanced_search_url @q = q || params[:q] @query_param = query_param @search_field = search_field || params[:search_field] @params = params.except(:q, :search_field, :utf8, :page) @prefix = prefix @classes = classes @method = method @autocomplete_path = autocomplete_path @autofocus = autofocus @i18n = i18n @form_options = end |
Instance Method Details
#advanced_search_enabled? ⇒ Boolean
59 60 61 |
# File 'app/components/blacklight/search_bar_component.rb', line 59 def advanced_search_enabled? blacklight_config.advanced_search.enabled end |
#autocomplete_path ⇒ Object
rubocop:enable Metrics/ParameterLists
36 37 38 39 40 |
# File 'app/components/blacklight/search_bar_component.rb', line 36 def autocomplete_path return nil unless blacklight_config.autocomplete_enabled @autocomplete_path end |
#autofocus ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/blacklight/search_bar_component.rb', line 42 def autofocus if @autofocus.nil? blacklight_config. && controller.is_a?(Blacklight::Catalog) && controller.action_name == "index" && !controller.has_search_parameters? else @autofocus end end |
#search_fields ⇒ Object
53 54 55 56 57 |
# File 'app/components/blacklight/search_bar_component.rb', line 53 def search_fields @search_fields ||= blacklight_config.search_fields.values .select { |field_def| helpers.should_render_field?(field_def) } .collect { |field_def| [helpers.label_for_search_field(field_def.key), field_def.key] } end |