Class: PhlexKit::DataTableSearch

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/data_table/data_table_search.rb

Overview

Debounced GET search form targeting the table's turbo-frame. Extra filter params survive via preserved_params: hidden inputs; focus/caret survive the frame swap (see the search controller). See data_table.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(path:, name: "search", value: nil, frame_id: nil, placeholder: "Search...", debounce: 300, preserved_params: {}, **attrs) ⇒ DataTableSearch

Returns a new instance of DataTableSearch.



6
7
8
9
10
11
12
13
14
15
# File 'app/components/phlex_kit/data_table/data_table_search.rb', line 6

def initialize(path:, name: "search", value: nil, frame_id: nil, placeholder: "Search...", debounce: 300, preserved_params: {}, **attrs)
  @path = path
  @name = name
  @value = value
  @frame_id = frame_id
  @placeholder = placeholder
  @debounce = debounce
  @preserved_params = preserved_params
  @attrs = attrs
end

Instance Method Details

#view_templateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/phlex_kit/data_table/data_table_search.rb', line 17

def view_template
  form(**mix({ class: "pk-data-table-search", method: "get", action: @path, data: form_data }, @attrs)) do
    render Input.new(
      type: :search,
      name: @name,
      value: @value,
      placeholder: @placeholder,
      autocomplete: "off"
    )
    @preserved_params.each do |k, v|
      next if v.nil? || (v.respond_to?(:empty?) && v.empty?)
      next if k.to_s == @name
      input(type: :hidden, name: k.to_s, value: v.to_s)
    end
  end
end