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

Source

const Type beanType

The bean type this FormBean represents.

createBean

Source

Obj createBean([Str:Obj?]? extraProps := null)

Creates an instance of beanType with all the field values set to the form field values. Uses afBeanUtils::BeanProperties.create().

This should only be called after validateForm().

Any extra properties passed in will also be set.

errorMsgs

Source

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

Source

@Inject { optional=true }
ErrorSkin? errorSkin

The ErrorSkin used to render error messages.

formFields

Source

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

Source

Bool hasErrors()

Returns true if any form fields are in error, or if any extra error messages have been added to this

make

Source

new make(Type beanType, |This in)

Deconstructs the given form bean type to a map of FormFields.

messages

Source

Str:Str 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

Source

Str renderBean(Obj? bean)

Renders the form bean to a HTML form.

If the given bean is null then values are taken from the form fields. Do so if you're re-rendering a form with validation errors.

renderErrors

Source

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

Source

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 to Submit.

updateBean

Source

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

Source

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.