Class: PhlexKit::DataTableSearch
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::DataTableSearch
- 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
-
#initialize(path:, name: "search", value: nil, frame_id: nil, placeholder: "Search...", debounce: 300, preserved_params: {}, method: "get", action: nil, **attrs) ⇒ DataTableSearch
constructor
method:/action: are kit-owned (a GET form targeting
path:) — named kwargs so a caller override lands in @method/@action directly instead of fusing with the generated defaults viamix("get post"). - #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(path:, name: "search", value: nil, frame_id: nil, placeholder: "Search...", debounce: 300, preserved_params: {}, method: "get", action: nil, **attrs) ⇒ DataTableSearch
method:/action: are kit-owned (a GET form targeting path:) — named
kwargs so a caller override lands in @method/@action directly instead
of fusing with the generated defaults via mix ("get post").
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/components/phlex_kit/data_table/data_table_search.rb', line 9 def initialize(path:, name: "search", value: nil, frame_id: nil, placeholder: "Search...", debounce: 300, preserved_params: {}, method: "get", action: nil, **attrs) @path = path @name = name @value = value @frame_id = frame_id @placeholder = placeholder @debounce = debounce @preserved_params = preserved_params @method = method @action = action || @path @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/components/phlex_kit/data_table/data_table_search.rb', line 22 def view_template form(**mix({ class: "pk-data-table-search", method: @method, action: @action, 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 |