Class: Forms::ChoicesSelect
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Forms::ChoicesSelect
- 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
-
#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
constructor
A new instance of ChoicesSelect.
- #view_template ⇒ Object
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, **) @modifiers = modifiers @name = name @id = id @choices = choices @selected = selected @multiple = multiple @searchable = searchable @remove_item_button = .nil? ? multiple : @placeholder = placeholder @include_blank = include_blank @prompt = prompt @error = error @disabled = disabled @required = required @options = super() end |
Instance Method Details
#view_template ⇒ Object
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 |