abstract class Kemal::Form::Field
- Kemal::Form::Field
- Reference
- Object
Overview
Super class of all form fields.
Custom form fields should inherit from Kemal::Form::Field
.
Direct Known Subclasses
- Kemal::Form::CheckboxField
- Kemal::Form::EmailField
- Kemal::Form::HiddenField
- Kemal::Form::NumberField
- Kemal::Form::PasswordField
- Kemal::Form::RadioField
- Kemal::Form::SelectField
- Kemal::Form::TextAreaField
- Kemal::Form::TextField
Defined in:
kemal-form/field.crConstructors
-
.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)
Initializes a new form field with the given id, name, attrs, value, required, label and validators.
Instance Method Summary
-
#add_error(message : String)
Adds error to the field.
-
#attrs : Hash(String, String)
Returns the additional attributes added to the field.
-
#errors : Array(String)
Returns the field errors added by the field validators.
-
#id : String
Returns the value of the field's id attribute.
-
#label : Form::Label | Nil
Returns the field's label.
-
#name : String
Returns the value of the field's name attribute.
-
#required : Bool
Returns whether the field's required attribute should be set.
-
#validate : Bool
Validates the field.
-
#validators : Array(Kemal::FormValidator::Validator)
Returns the field's validators.
-
#value : String
Returns the value of the field.
-
#value=(value : String)
Returns the value of the field.
Constructor Detail
def self.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)
#
Initializes a new form field with the given id, name, attrs, value, required, label and validators.
Instance Method Detail
def add_error(message : String)
#
Adds error to the field.
post "/login" do |env|
form = SignUpForm.new env
form.valid?
if username_already_exist
form.username.add_error "Username already exist"
...
end
...
end
...
end