Class: Templet::Utils::HtmlSearchForm

Inherits:
Component::Partial
  • Object
show all
Includes:
Constants, Mixins::Bs
Defined in:
app/helpers/templet/utils/html_search_form.rb,
lib/generators/templet/templates/core/templet/utils/html_search_form.rb

Overview

Renders a form (inline) for string searches, primarily for index actions.

Constant Summary

Constants included from Constants

Constants::BS_BUTTON, Constants::BS_BUTTON_BLOCK, Constants::BS_BUTTON_DROPDOWN, Constants::BS_BUTTON_GROUP, Constants::BS_BUTTON_GROUP_JUSTIFIED, Constants::BS_BUTTON_GROUP_VERTICAL, Constants::BS_BUTTON_SIZE, Constants::BS_BUTTON_SUBMIT, Constants::BS_BUTTON_SUBMIT_SEARCH, Constants::BS_BUTTON_TOOLBAR, Constants::BS_BUTTON_TYPE, Constants::BS_COL, Constants::BS_COL_OFFSET, Constants::BS_FORM, Constants::BS_FORM_INLINE, Constants::BS_LIST_GROUP, Constants::BS_LIST_GROUP_ITEM, Constants::BS_LIST_INLINE, Constants::BS_LIST_UNSTYLED, Constants::BS_NAV, Constants::BS_NAV_PILLS, Constants::BS_NAV_PILLS_STACKED, Constants::BS_NAV_TABS, Constants::BS_PANEL, Constants::BS_PANEL_BODY, Constants::BS_PANEL_HEADING, Constants::BS_PANEL_TITLE, Constants::BS_SELECTED, Constants::BS_TABLE, Constants::BS_TOOLBAR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Bs::Grid

#col_class, #col_offset_class, #in_cols, #in_rows

Methods included from Mixins::Bs::Lists

#button_group_dropdown, #in_button_group, #in_button_toolbar, #in_html_list, #in_list_group_buttons, #in_list_group_links, #in_nav

Methods included from Mixins::HtmlPresenters

#default_list_class, #default_table_class, #get_list_class, #html_definition_list, #html_form, #html_list, #html_table, #stacked_list_class

Class Method Details

.call(renderer, model, parent = nil, scope: nil, action: nil, remote: nil) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'app/helpers/templet/utils/html_search_form.rb', line 34

def self.call(renderer, model, parent=nil, scope: nil,
                                           action: nil,
                                           remote: nil)
  rest_path = Links::RestPath.new(model, parent, scope: scope)

  path = action ? rest_path.action(action) : rest_path.index

  new(renderer).(path, remote: remote)
end

Instance Method Details

#call(url, field_name: 'q', submit_text: 'Search', label: nil, remote: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/templet/utils/html_search_form.rb', line 10

def call(url, field_name: 'q', submit_text: 'Search',
              label: nil, remote: false)
  label ||= submit_text.underscore

  super() do
    Forms::BsForm.new(renderer).(**form_opts(url, remote)) do |renderer|
      group = Forms::BsFormGroup.(renderer)

      btn_class = "#{BS_BUTTON_SUBMIT_SEARCH} #{BS_BUTTON}-#{group.height}"
      submit = button(submit_text, btn_class, type: 'submit')

      [
        group.(field_name, label_name: label) do |renderer, record_name|
          renderer.call do
            text_field record_name, field_name, value: params[field_name],
                                                class: group.field_class
          end
        end,
        submit
      ]
    end
  end
end