class Kemal::Form::SelectField
- Kemal::Form::SelectField
- Kemal::Form::Field
- Reference
- Object
Overview
A select form field.
class SelectForm < Kemal::Form
field colors : Kemal::Form::SelectField,
options: [
Kemal::Form::SelectField::Option.new("blue"),
Kemal::Form::SelectField::Option.new("green"),
Kemal::Form::SelectField::Option.new("red"),
Kemal::Form::SelectField::Option.new("yellow")
]
end
will render
<select id="colors" name="colors">
<option value="blue">blue</option>
<option value="green">green</option>
<option value="red">red</option>
<option value="yellow">yellow</option>
</select>
Defined in:
kemal-form/fields/select.crConstructors
-
.new(id, name, value, required, label, attrs = {} of String => String, validators = [] of Kemal::FormValidator::Validator, options : Array(Kemal::Form::SelectField::Option) = [] of Option)
Initializes a new
SelectField
.
Instance Method Summary
-
#options : Array(Option)
Returns the field's options.
-
#to_s(io : IO)
Appends a short String representation of this object which includes its class name and its object address.
Instance methods inherited from class Kemal::Form::Field
add_error(message : String)
add_error,
attrs : Hash(String, String)
attrs,
errors : Array(String)
errors,
id : String
id,
label : Form::Label | Nil
label,
name : String
name,
required : Bool
required,
validate : Bool
validate,
validators : Array(Kemal::FormValidator::Validator)
validators,
value : String
value,
value=(value : String)
value=
Constructor methods inherited from class Kemal::Form::Field
new(id : String, name : String, value : String, required : Bool, label : Nil | Kemal::Form::Label = nil, attrs : Hash(String, String) = {} of String => String, validators : Array(Kemal::FormValidator::Validator) = [] of Kemal::FormValidator::Validator)
new
Constructor Detail
def self.new(id, name, value, required, label, attrs = {} of String => String, validators = [] of Kemal::FormValidator::Validator, options : Array(Kemal::Form::SelectField::Option) = [] of Option)
#
Initializes a new SelectField
.
Instance Method Detail
def to_s(io : IO)
#
Description copied from class Reference
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>