Class: RubyUI::DataTableSearch

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_ui/data_table/data_table_search.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

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.



5
6
7
8
9
10
11
12
13
14
# File 'lib/ruby_ui/data_table/data_table_search.rb', line 5

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
  super(**attrs)
end

Instance Method Details

#view_templateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby_ui/data_table/data_table_search.rb', line 16

def view_template
  form_attrs = {method: "get", action: @path}
  form_attrs[:data] = form_data

  form(**attrs.merge(form_attrs)) do
    render RubyUI::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