classafFormBean::FormField
sys::Obj afFormBean::FormField
Holds all the meta data required to convert a field on a Fantom object to HTML and back again.
- attributes
Str? attributes
HTML attribute. Any other miscellaneous attributes that should be rendered on the
<input>
. Example:attributes = "data-foo='bar'"
- autocomplete
Str? autocomplete
HTML attribute. The value to render as an
autocomplete
attribute on the<input>
. See autocomplete on whatwg and MDN for valid values. Example:autocomplete = "cc-number"
- blankLabel
Str? blankLabel
Used by the
<select>
renderer. This is the label to display in the blank option.leave as null to use
OptionsProvider.blankLabel
value.- css
Str? css
HTML attribute. The value to render as a CSS
class
attribute on the<input>
.- disabled
Bool disabled
HTML attribute. If true then a disabled attribute is rendered on the
<input>
.- doHtmlValidation
virtual Void doHtmlValidation()
Performs basic HTML5 validation.
- errMsg
Str? errMsg
The error message associated with this field.
Setting this to a non-null value invalidate the form field.
- field
Field field
The Fantom field this
FormField
represents.- formBean
FormBean formBean
A link back to the owning
FormBean
instance.- formData
Obj? formData
Used as temporary store when uploading binary data, such as
Bufs
andFiles
. Contains the value that the form field will be set to.- formValue
Str? formValue
The
Str
value that will be rendered in the HTML form. You may set this value before the form is rendered to set a default value.If the
formValue
isnull
then the field value is used instead and converted byvalueEncoder
.This
formValue
is also set during form validation so any user entered values are re-rendered should the form be re-displayed.- hint
Str? hint
If non-null an extra
<div>
is rendered after the<input>
to supply a helpful hint. The hint is usually rendered with theformBean-hint
CSS class.- inputSkin
InputSkin? inputSkin
The
InputSkin
used to render the field to HTML.If
null
then a defaultInputSkin
is chosen based on thetype
attribute.- invalid
Bool invalid
Is this form field invalid?
Setting this to
false
also clears anyerrMsg
.- label
Str? label
The label to display next to the
<input>
.If
null
then it defaults to a human readable version of the field name.- make
new make(Field field, FormBean formBean, |This in)
Create
FormField
instances via IoC:formField := scope.build(FormField#, [field, formBean])
- max
Obj? max
HTML5 validation attribute. Sets the maximum value (inclusive) for numbers (
Int
) and dates (Date
).- maxLength
Int? maxLength
HTML5 validation attribute. Sets the maximum value (inclusive). May be an
Int
,Date
,DateTime
, orStr
.- min
Obj? min
HTML5 validation attribute. Sets the minimum value (inclusive). May be an
Int
,Date
,DateTime
, orStr
.- minLength
Int? minLength
HTML5 validation attribute. Sets the minimum length (inclusive) a string should be.
- msg
Str? msg(Str key, Obj? arg1 := null, Obj? arg2 := null, Obj? arg3 := null)
Returns a message for the given field. Messages are looked up in the following order:
<bean>.<field>.<key>
<field>.<key>
<key>
And the following substitutions are made:
${label} -> formField.label
${value} -> formField.formValue
${arg1} -> arg1.toStr
${arg2} -> arg2.toStr
${arg3} -> arg3.toStr
The form value is substituted for
${value}
because it is intended for use by validation msgs.Returns
null
if a msg could not be found.- optionsProvider
OptionsProvider? optionsProvider
Used by the
<select>
renderer. TheOptionsProvider
used to supply option values when rendering<select>
tags.If
null
then a defaultOptionsProvider
is chosen based on the field type.- pattern
Regex? pattern
HTML5 validation attribute. Sets a regular expression that the (stringified) value should match. Starting
^
and ending$
characters are implicit and not required.- placeholder
Str? placeholder
HTML attribute. The value to render as a
placeholder
attribute on the<input>
.- populate
This populate()
Populates this
FormField
instance with values from the@HtmlInput
facet (if any) and message values.- render
virtual Str render(Obj? bean := null)
Hook to render this field to HTML. By default this defers rendering to an
InputSkin
.Override to perform custom field rendering.
- required
Bool? required
HTML5 validation attribute. Set to
true
to mark the input as required. Ifnull
(the default) then the input is required if the field is non-nullable.- set
@
Operator
Void set(Str key, Obj? val)Sets the given form field message. Messages are stored in the FormBean under the key:
<bean>.<field>.<key>
null
values are removed from the messges map.- showBlank
Bool? showBlank
Used by the
<select>
renderer. Set totrue
to show a blank value at the start of the options list.leave as null to use
OptionsProvider.showBlank
value.- stash
A general stash, handy for passing data to static validate methods.
- step
Int? step
HTML5 validation attribute. Defines the interval for a numeric input.
- toClient
Converts the given value to a string using the preferred
ValueEncoder
.- toValue
Converts the given client value (string) to a server side object using the preferred
ValueEncoder
.- type
Str? type
HTML attribute. The type of input to render.
If
null
then it defaults totext
.- validate
virtual Void validate()
Validates this form field. Calls
doHtmlValidation()
and then any static@Validate
method that corresponds to this field.@Validate
methods may checkinvalid
anderrMsg
to ascertain if any previous validation failed.After validation check the value of the
invalid
anderrMsg
fields.- validationMethod
Method? validationMethod
A static method that performs extra server side validation.
- valueEncoder
Obj? valueEncoder
The
afBedSheet::ValueEncoder
used to convert the field value to and from aStr
.If
null
then a defaultValueEncoder
based on the field type is chosen from BedSheet'sValueEncoders
service.- viewOnly
Bool? viewOnly
If
true
then the field is rendered into the HTML form as normal, but no attempt is made to validate the form value or decode it back to a Fantom value.Useful for rendering static, read only, HTML associated with the field.