Class: Brut::FrontEnd::Forms::ButtonInputDefinition

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

Overview

Defines a button to be used to submit a form (as opposed to an <input type="submit">). This is needed when the name/value of the button should be submitted witih the form.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Brut::Framework::FussyTypeEnforcement

#type!

Constructor Details

#initialize(name:, array: false) ⇒ ButtonInputDefinition

Create a ButtonInputDefinition.

Parameters:

  • name (String)

    Name of the button (required)

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

    If true, the form will expect multiple values for this input. The values will be available as an array. Any values omitted by the user will be present as empty strings.

See Also:



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

def initialize(
  name:,
  array: false
)
  name  = name.to_s
  @name  = type!(name,  String,        "name",  required: true)
  @array = type!(array, [true, false], "array", required: true)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/brut/front_end/forms/button_input_definition.rb', line 6

def name
  @name
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


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

def array? = @array

#make_input(value:, index:) ⇒ Object

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

Parameters:

  • value (String)

    the value to give this input initially.

  • index (Integer)

    the index of this input, if it is part of an array of inputs. nil is allowed only if the input definition is not for an array.



30
31
32
# File 'lib/brut/front_end/forms/button_input_definition.rb', line 30

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