Class: Fluxbit::Form::SelectComponent

Inherits:
TextFieldComponent
  • Object
show all
Defined in:
app/components/fluxbit/form/select_component.rb

Overview

The Fluxbit::Form::SelectComponent is a styled dropdown/select field for forms. It supports standard, grouped, and time zone options, integrates with Rails form builders, and provides flexible props for prompt, disabled/selected options, helper text, and more.

Examples:

Basic usage

= render Fluxbit::Form::SelectComponent.new(name: :role, options: ["Admin", "User", "Guest"], label: "User Role")

See Also:

  • For detailed documentation and examples.

Instance Method Summary collapse

Constructor Details

#initialize(**props) ⇒ SelectComponent

Initializes the select component with the given properties.



25
26
27
28
29
30
31
32
33
# File 'app/components/fluxbit/form/select_component.rb', line 25

def initialize(**props)
  super(**props)
  @grouped = @props.delete(:grouped) || false
  @time_zone = @props.delete(:time_zone) || false
  @select_options = @props.delete(:select_options) || {}
  @choices = @props.delete(:choices) || nil
  @options = @props.delete(:options) || {}
  @options = ::ActiveSupport::TimeZone.all if @time_zone
end

Instance Method Details

#build_options_for_selectObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/components/fluxbit/form/select_component.rb', line 52

def build_options_for_select
  if @grouped
    grouped_options_for_select(
      @options,
      @selected,
      disabled: @disabled_options,
      prompt: @prompt,
      divider: @divider
    )
  elsif @time_zone
    time_zone_options_for_select(@selected)
  else
    options_for_select(@options, selected: @selected, disabled: @disabled_options)
  end
end

#inputObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/fluxbit/form/select_component.rb', line 35

def input
  if @form.present? && @attribute.present?
    @form.select(
      @attribute,
      build_options_for_select,
      @select_options,
      @props
    )
  else
    select_tag(
      @name,
      build_options_for_select,
      @props
    )
  end
end