Flow of Control
The flow of control through Albatross forms is tied in with Albatross's flow of control.
A mistake I have made a couple of times is to reinitialise the form from the model part way through the user's interaction with the page (ie, before they've saved it). It winds up losing any changes that the user has made on the form. The lesson here is that the form should only be loaded from the model once when the user starts interacting with it; don't reload it on each page refresh.
- Constructor
- Create the form itself.
- Load from model
- I normally do this in the constructor.
- Display the form
Render the form to the web page, typically using <alx-form name="model_form" errors> in your Albatross template for the page.
- Validate
Check that the data that the user entered is correct. The call to validate will raise a FormValidationError exception.
- Merge
- Update the model with the data fields collected from the form.