Class: Brut::FrontEnd::Forms::SelectInputDefinition

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

Overview

Defines a <select> for a form, but not it's current runtime state. SelectInput is used to understand the current state or value of a select.

Note that a select input definition is defining an HTML <select>, not a generic attribute. Thus, the only constraints you can place on an input are those that the browser supports. If your form needs server side validation, you can accomplish that in a lot of ways, such as implementing a BackEnd::Validators::FormValidator, or calling Brut::FrontEnd::Form#server_side_constraint_violation directly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Brut::Framework::FussyTypeEnforcement

#type!

Constructor Details

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

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, 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.



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

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)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/brut/front_end/forms/select_input_definition.rb', line 9

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



9
10
11
# File 'lib/brut/front_end/forms/select_input_definition.rb', line 9

def required
  @required
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


21
# File 'lib/brut/front_end/forms/select_input_definition.rb', line 21

def array? = @array

#make_input(value:, index:) ⇒ Object

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



24
25
26
# File 'lib/brut/front_end/forms/select_input_definition.rb', line 24

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