Class: Brut::FrontEnd::Forms::RadioButtonGroupInputDefinition

Inherits:
Object
  • Object
show all
Includes:
Brut::Framework::FussyTypeEnforcement
Defined in:
lib/brut/front_end/forms/radio_button_group_input_definition.rb

Overview

Defines a radio button group for a form, but not it's runtime state (which includes how many radio buttons would need to be rendered). See RadioButtonInput.

Note that this ultimately defines the contents for a <input type="radio"> tag, so the constraints you can place are only those supported by the browser. Also note that arrays of radio button groups are not currently supported.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Brut::Framework::FussyTypeEnforcement

#type!

Constructor Details

#initialize(name:, required: true, array: false) ⇒ RadioButtonGroupInputDefinition

Create the input definition

Parameters:

  • name (String)

    Name of the input (required)

  • required (true|false) (defaults to: true)

    true if this field is required, false otherwise. Default is true.

  • array (true|false) (defaults to: false)

    If true, an error is raised as this is not yet supported



13
14
15
16
17
18
19
20
21
# File 'lib/brut/front_end/forms/radio_button_group_input_definition.rb', line 13

def initialize(name:, required: true, array: false)
  name = name.to_s
  @name     = type!( name      , String        , "name",     required: true)
  @required = type!( required  , [true, false] , "required", required: true)
  @array    = type!( array     , [true, false] , "array", required: true)
  if @array
    raise Brut::Framework::Errors::NotImplemented, "Arrays of radio button groups are not yet supported"
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/brut/front_end/forms/radio_button_group_input_definition.rb', line 8

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



8
9
10
# File 'lib/brut/front_end/forms/radio_button_group_input_definition.rb', line 8

def required
  @required
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


23
# File 'lib/brut/front_end/forms/radio_button_group_input_definition.rb', line 23

def array? = @array

#make_input(value:, index:) ⇒ Object

Create an Input based on this defitition, initializing it with the given value.



26
27
28
# File 'lib/brut/front_end/forms/radio_button_group_input_definition.rb', line 26

def make_input(value:, index:)
  Brut::FrontEnd::Forms::RadioButtonGroupInput.new(input_definition: self, value:, index:)
end