Class: Forms::Select

Inherits:
Phlex::HTML
  • Object
show all
Includes:
PhlexForms::DelegatedField
Defined in:
lib/forms/select.rb

Overview

A model-bound native <select>. Delegates the element + variants to DaisyUI::Select (daisyui v5 puts the select class on the element itself) and renders the options from choices inside its block.

Constant Summary

Constants included from PhlexForms::DelegatedField

PhlexForms::DelegatedField::IGNORED_MODIFIERS

Instance Method Summary collapse

Constructor Details

#initialize(*modifiers, name: nil, id: nil, choices: [], selected: nil, include_blank: false, prompt: nil, error: false, disabled: false, required: false, full_width: true, **attributes) ⇒ Select

Returns a new instance of Select.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/forms/select.rb', line 10

def initialize(*modifiers, name: nil, id: nil, choices: [], selected: nil,
               include_blank: false, prompt: nil, error: false, disabled: false,
               required: false, full_width: true, **attributes)
  @modifiers = normalize_modifiers(modifiers)
  @name = name
  @id = id
  @choices = choices
  @selected = selected
  @include_blank = include_blank
  @prompt = prompt
  @error = error
  @disabled = disabled
  @required = required
  @full_width = full_width
  @attributes = attributes
  super()
end

Instance Method Details

#view_templateObject



28
29
30
31
32
33
# File 'lib/forms/select.rb', line 28

def view_template
  render DaisyUI::Select.new(*daisy_modifiers, **binding_attributes) do |el|
    render_prompt(el) if @prompt || @include_blank
    render_choices(el)
  end
end