Class: Ariadne::Forms::Dsl::RadioButtonGroupInput

Inherits:
Input
  • Object
show all
Defined in:
lib/ariadne/forms/dsl/radio_button_group_input.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Input

Input::DEFAULT_SIZE, Input::SIZE_MAPPINGS, Input::SIZE_OPTIONS, Input::SPACE_DELIMITED_ARIA_ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Input

#base_id, #builder, #caption, #form, #form_control, #ids, #input_attributes, #label_attributes, #validation_message

Instance Method Summary collapse

Methods inherited from Input

#add_input_aria, #add_input_classes, #add_input_data, #caption?, #caption_id, #caption_template?, #disabled?, #hidden?, #id, #input?, #invalid?, #merge_input_attributes!, #remove_input_data, #render_caption_template, #required?, #size, #supports_validation?, #valid?, #validation_arguments, #validation_error_icon_target, #validation_id, #validation_message_arguments, #validation_messages, #validation_success_icon_target

Methods included from ClassNameHelper

#merge_class_names

Constructor Details

#initialize(name:, label: nil, **options) {|_self| ... } ⇒ RadioButtonGroupInput

Returns a new instance of RadioButtonGroupInput.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
16
17
18
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 10

def initialize(name:, label: nil, **options)
  @name = name
  @label = label
  @radio_buttons = []

  super(**options)

  yield(self) if block_given?
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 8

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 8

def name
  @name
end

#radio_buttonsObject (readonly)

Returns the value of attribute radio_buttons.



8
9
10
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 8

def radio_buttons
  @radio_buttons
end

Instance Method Details

#autofocus!Object



32
33
34
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 32

def autofocus!
  @radio_buttons.first&.autofocus!
end

#focusable?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 36

def focusable?
  true
end

#radio_button(**options, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 40

def radio_button(**options, &block)
  @radio_buttons << RadioButtonInput.new(
    builder: @builder, form: @form, name: @name, disabled: disabled?,
    **options,
    &block
  ).to_component
end

#to_componentObject



20
21
22
23
24
25
26
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 20

def to_component
  component = Ariadne::Form::RadioButtonGroup::Component.new(name:, label:, **@options)
  @radio_buttons.each do |radio_button|
    component.rendered_radio_button(radio_button)
  end
  component
end

#typeObject



28
29
30
# File 'lib/ariadne/forms/dsl/radio_button_group_input.rb', line 28

def type
  :radio_button_group
end