Class: Forms::ChoicesSelect

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/forms/choices_select.rb

Overview

A searchable/multi-select <select> enhanced by the choices.js Stimulus controller (shipped with the gem). Renders a normal <select> server-side; the choices controller upgrades it on connect. choices.js replaces the element, so size/color positional modifiers are passed as data values and applied to the choices.js wrapper by the controller (not as daisyui classes).

Constant Summary collapse

SIZE_MODIFIERS =
%i[xs sm md lg xl].freeze
COLOR_MODIFIERS =
%i[primary secondary accent neutral info success warning error].freeze

Instance Method Summary collapse

Constructor Details

#initialize(*modifiers, name: nil, id: nil, choices: [], selected: nil, multiple: false, searchable: false, remove_item_button: nil, placeholder: nil, include_blank: false, prompt: nil, error: false, disabled: false, required: false, **options) ⇒ ChoicesSelect

Returns a new instance of ChoicesSelect.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/forms/choices_select.rb', line 13

def initialize(*modifiers, name: nil, id: nil, choices: [], selected: nil, multiple: false,
               searchable: false, remove_item_button: nil, placeholder: nil,
               include_blank: false, prompt: nil, error: false, disabled: false, required: false, **options)
  @modifiers = modifiers
  @name = name
  @id = id
  @choices = choices
  @selected = selected
  @multiple = multiple
  @searchable = searchable
  @remove_item_button = remove_item_button.nil? ? multiple : remove_item_button
  @placeholder = placeholder
  @include_blank = include_blank
  @prompt = prompt
  @error = error
  @disabled = disabled
  @required = required
  @options = options
  super()
end

Instance Method Details

#view_templateObject



34
35
36
37
38
39
# File 'lib/forms/choices_select.rb', line 34

def view_template
  select(**attrs) do
    render_prompt if @prompt || @include_blank
    render_choices
  end
end