Instances of Field subclasses are generally built by HTML::FormHandler from 'has_field' declarations or the field_list,
but they can also be constructed using new for test purposes (since there's no standard way to add a field to a form after construction).

This is the base class for form fields. The 'type' of a field class is used in the FormHandler field_list or has_field to identify which field class to load from the 'field_name_space' (or directly, when prefixed with '+'). If the type is not specified, it defaults to Text.

Set the 'inactive' attribute to 1 if this field is inactive. The 'inactive' attribute that isn't set or is set to 0 will make a field 'active'. This provides a way to define fields in the form and selectively set them to inactive. There is also an '_active' attribute, for internal use to indicate that the field has been activated/inactivated on 'process' by the form's 'active'/'inactive' attributes.

You can use the is_inactive and is_active methods to check whether this particular field is active.

The value as it would come from or go into the database, after being acted on by inflations/deflations and transforms. Used to construct the $form->values hash. Validation and constraints act on 'value'.

Values used to fill in the form. Read only. Use a deflation to get from 'value' to 'fif' if an inflator was used. Use 'fif_from_value' attribute if you want to use the field 'value' to fill in the form.

Returns the error list for the field. Also provides 'num_errors', 'has_errors', 'push_errors' and 'clear_errors' from Array trait. Use 'add_error' to add an error to the array if you want to use a MakeText language handle. Default is an empty list.

Note that the 'id' and 'type' attributes are not set using element_attr. Use the field's 'id' attribute (or 'build_id_method') to set the id.

The 'label_attr' hashref is for label attributes, and the 'wrapper_attr' is for attributes on the wrapping element (a 'div' for the standard 'simple' wrapper).

A 'javascript' key in one of the '_attr' hashes will be inserted into the element as-is.

The following are used in rendering HTML, but are handled specially.

label - Text label for this field. Defaults to ucfirst field name.
build_label_method - coderef for constructing the label
wrap_label_method - coderef for constructing a wrapped label
id - Useful for javascript (default is html_name. to prefix with
form name, use 'html_prefix' in your form)
build_id_method - coderef for constructing the id
render_filter - Coderef for filtering fields before rendering. By default
changes >, <, &, " to the html entities
disabled - Boolean to set field disabled

The order attribute may be used to set the order in which fields are rendered.

order - Used for sorting errors and fields. Built automatically,
but may also be explicitly set

The following are discouraged. Use 'element_attr', 'label_attr', and 'wrapper_attr' instead.

Rendering of the various HTML attributes is done by calling the 'process_attrs' function (from HTML::FormHandler::Render::Util) and passing in a method that adds in error classes, provides backward compatibility with the deprecated attributes, etc.

('element_wrapper' is for an inner div around the input element, not including the label. Used for Bootstrap3 rendering, but also available in the Simple wrapper.) The slots for the class attributes are arrayrefs; they will coerce a string into an arrayref. In addition, these 'wrapping methods' call a hook method in the form class, 'html_attributes', which you can use to customize and localize the various attributes. (Field types: 'element', 'wrapper', 'label')

A hashref containing flags and strings for use in the rendering code. The value of a tag can be a string, a coderef (accessed as a method on the field) or a block specified with a percent followed by the blockname ('%blockname').

Retrieve a tag with 'get_tag'. It returns a '' if the tag doesn't exist.

The 'widget' attribute is used in rendering, so if you are not using FormHandler's rendering facility, you don't need this attribute. It is used in generating HTML, in templates and the rendering roles. Fields of different type can use the same widget.

This attribute is set in the field classes, or in the fields defined in the form. If you want a new widget type, create a widget role, such as MyApp::Form::Widget::Field::MyWidget. Provide the name space in the 'widget_name_space' attribute, and set the 'widget' of your field to the package name after the Field/Form/Wrapper:

password - prevents the entered value from being displayed in the form
writeonly - The initial value is not taken from the database
noupdate - Do not update this field in the database (does not appear in $form->value)

Supply a coderef (which will be a method on the field) with 'default_method' or the name of a form method with 'set_default' (which will be a method on the form). If not specified and a form method with a name of default_<field_name> exists, it will be used.

Provide an initial value just like the 'set_default' method, except in the field declaration:

has_field 'bax' => ( default => 'Default bax' );

FormHandler has flipped back and forth a couple of times about whether a default specified in the has_field definition should override values provided in an initial item or init_object. Sometimes people want one behavior, and sometimes the other. Now 'default' does *not* override.

If you pass in a model object with item => $row or an initial object with init_object => {....} the values in that object will be used instead of values provided in the field definition with 'default' or 'default_fieldname'. If you want defaults that override or supplement the item/init_object, you can use the form flags 'use_defaults_over_obj', 'use_init_obj_over_item', and 'use_init_obj_when_no_accessor_in_item'.

You could also put your defaults into your row or init_object instead.

This is deprecated; look into using 'use_defaults_over_obj' or 'use_init_obj_over_item' flags instead. They allow using the standard 'default' attribute.

Allows setting defaults which will override values provided with an item/init_object. (And only those. Will not be used for defaults without an item/init_object.)

has_field 'quux' => ( default_over_obj => 'default quux' );

At this time there is no equivalent of 'set_default', but the type of the attribute is not defined so you can provide default values in a variety of other ways, including providing a trait which does 'build_default_over_obj'. For examples, see tests in the distribution.

Fields that contain 'empty' values such as '' are changed to undef in the validation process. If this flag is set, the value is not changed to undef. If your database column requires an empty string instead of a null value (such as a NOT NULL column), set this attribute.

Normally if you have a deflation, you will need a matching inflation. There are two different flavors of inflation/deflation: one for inflating values to a format needed for validation and deflating for output, the other for inflating the initial provided values (usually from a database row) and deflating them for the 'values' returned.

Supply a coderef (which will be a method on the field) with 'validate_method' or the name of a form method with 'set_validate' (which will be a method on the form). If not specified and a form method with a name of validate_<field_name> exists, it will be used.

Periods in field names will be replaced by underscores, so that the field 'addresses.city' will use the 'validate_addresses_city' method for validation.