abstract class Kemal::Form::Field

Overview

Super class of all form fields.

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

Direct Known Subclasses

Defined in:

kemal-form/field.cr

Constructors

Instance Method Summary

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.


[View source]

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

[View source]
def attrs : Hash(String, String) #

Returns the additional attributes added to the field.


[View source]
def errors : Array(String) #

Returns the field errors added by the field validators.


[View source]
def id : String #

Returns the value of the field's id attribute.


[View source]
def label : Form::Label | Nil #

Returns the field's label.


[View source]
def name : String #

Returns the value of the field's name attribute.


[View source]
def required : Bool #

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


[View source]
def validate : Bool #

Validates the field.


[View source]
def validators : Array(Kemal::FormValidator::Validator) #

Returns the field's validators.


[View source]
def value : String #

Returns the value of the field.


[View source]
def value=(value : String) #

Returns the value of the field.


[View source]