In many situations, you will want to set up forms to create or edit instances of custom data types. DRAW provides you with a helper to easily create forms.
Generate a form
Create a new custom data type, e.g.
Customer with some properties.
To generate a form for this component, open the menu and click on
Generate helper bricks and forms.
Form column of the popup, select the properties for which you want to generate a field.
The generator creates one field per property depending on its type.
By default, a form is generated with one property
Edited Object and three events
On Saved, and
Use a form
In a screen or in a visual component, you can then find the newly created form in the marketplace on the right. The form has two behaviors:
Edited Object is not set, the form is initially empty. Triggering the
Save event then creates a new object with its properties set to the values currently entered in the form. That new object is then stored in
Edited Object, such that you can retrieve it easily.
Edited Object is set, then the properties of the new object are loaded in the form. Triggering the
Save event then updates the object with the values currently entered in the form.
In case you want to trigger further actions upon save, the form also exposed two other events which are triggered upon save:
- If successful,
On Savedis called.
- If some error occurs,
On Erroris called.
Those behave like the
On Click of a button for example, and you can define your own behavior within the
Here is a schema representing that logic:
Modify a form
The form is automatically generated as a new brick in DRAW. That means that you can easily open it and modify it, in case you want to change its behavior. One typical example is if you need to add or remove some fields in the form, or which to change its appearance.
Edited Object behavior described above (create if not set, modify if set) is predefined in the generated form's
Save event. You may have to change that function, in case you add or remove fields within the form, or if you want to change its behavior. If you open the form, you can see there that the
Save event is already defined. Click on
f(x) button to edit it.