classafFormBean::FormBean
sys::Obj afFormBean::FormBean
Represents a Fantom object that can rendered as a HTML form, and reconstituted back to a Fantom object.
- beanType
const Type beanType
The bean type this
FormBean
represents.- createBean
Obj createBean([Str:Obj?]? extraProps := null)
Creates an instance of
beanType
with all the field values set to the form field values. UsesafBeanUtils::BeanProperties.create()
.This should only be called after
validateForm()
.Any extra properties passed in will also be set.
- errorMsgs
Str[] errorMsgs := Str[,]
You may set any extra (cross field validation) error messages here. They will be rendered along with the form field error messages.
- errorSkin
@
Inject { optional=true }
ErrorSkin? errorSkinThe
ErrorSkin
used to render error messages.- formFields
Field:FormField formFields := ... { private set }
The form fields that make up this form bean. The returned map is read only, but the
FormFields
themselves may still be manipulated.- hasErrors
Bool hasErrors()
Returns
true
if any form fields are in error, or if any extra error messages have been added to this- make
new make(Type beanType, |This in)
Deconstructs the given form bean type to a map of
FormFields
.- messages
The message map used to find strings for labels, placeholders, hints, and validation errors. Messages are read from (and overridden by) the following pod resource files:
<beanType.name>.properties
FormBean.properties
Note that property files must be in the same pod as the defining bean.
- renderBean
Renders the form bean to a HTML form.
If the given
bean
isnull
then values are taken from the form fields. Do so if you're re-rendering a form with validation errors.- renderErrors
Str renderErrors()
Renders form field errors (if any) to an unordered list. Delegates to a default instance of
ErrorSkin
which renders the following HTML:<div class='formBean-errors'> <div class='formBean-banner'>#BANNER</div> <ul> <li> Error 1 </li> <li> Error 2 </li> </ul> </div>
To change the banner message, set a message with the key
errors.banner
.- renderSubmit
Str renderSubmit()
Renders a simple submit button.
<div class='formBean-row submitRow'> <input type='submit' name='formBeanSubmit' class='submit' value='label'> </div>
The label is taken from the msg key
field.submit.label
and defaults toSubmit
.- updateBean
Obj updateBean(Obj bean, [Str:Obj?]? extraProps := null)
Updates the given bean instance with form field values. Uses
afBeanUtils::BeanProperties
.This should only be called after
validateForm()
.Any extra properties passed in will also be set.
- validateForm
Bool validateForm(Str:Str form)
Populates the form fields with values from the given
form
map and performs server side validation. Error messages are saved to the form fields.Returns
true
if all the values are valid,false
if not.It is safe to pass in
HttpRequest.form()
directly.