class

Kemal::Form::Field

Inherits Reference / Object

Super class of all form fields.

Custom form fields should inherit from Kemal::Form::Field.

Constructors

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.

Source

Instance methods

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
Source
attrs

Returns the additional attributes added to the field.

Source
errors

Returns the field errors added by the field validators.

Source
id

Returns the value of the field's id attribute.

Source
label

Returns the field's label.

Source
name

Returns the value of the field's name attribute.

Source
required

Returns whether the field's required attribute should be set.

Source
validate

Validates the field.

Source
validators

Returns the field's validators.

Source
value

Returns the value of the field.

Source
value=(value : String)

Returns the value of the field.

Source