You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.8 KiB
31 lines
1.8 KiB
2 years ago
|
---
|
||
|
parent: Generating forms
|
||
|
nav_order: 2
|
||
|
---
|
||
3 years ago
|
|
||
2 years ago
|
# Form runner
|
||
3 years ago
|
|
||
2 years ago
|
The Form runner is composed of:
|
||
|
|
||
|
Ruby classes:
|
||
3 years ago
|
|
||
3 years ago
|
- A singleton form handler that instantiates an instances of each form definition (config file we have) combined with the setup section that is common to all forms. This is created at rails boot time. (`app/models/form_handler.rb`)
|
||
|
- A `Form` class that is the entry point for parsing a form definition and handles most of the associated logic (`app/models/form.rb`)
|
||
2 years ago
|
- [`Section`](section), [`Subsection`](subsection), [`Page`](page) and [`Question`](question) classes (`app/models/form/`)
|
||
3 years ago
|
- Setup subsection specific instances (subclasses) of `Section`, `Subsection`, `Pages` and `Questions` (`app/form/setup/`)
|
||
|
|
||
|
ERB templates:
|
||
|
|
||
3 years ago
|
- The page view which is the main view for each form page (`app/views/form/page.html.erb`)
|
||
|
- Partials for each question type (radio, checkbox, select, text, numeric, date) (`app/views/form/`)
|
||
|
- Partials for specific question guidance (`app/views/form/guidance`)
|
||
|
- The check answers page which is the view for the answer summary page of each section (`app/views/form/check_answers.html.erb`)
|
||
|
|
||
3 years ago
|
Routes for each form page are generated by looping over each Page instance in each Form instance held by the form handler and defining a `GET` path. The corresponding controller method is also auto-generated with meta-programming via the same looping in `app/controllers/form_controller.rb`
|
||
3 years ago
|
|
||
3 years ago
|
All form pages submit to the same controller method (`app/controllers/form_controller.rb#submit_form`) which validates and persists the data, and then redirects to the next form page that identifies as `routed_to` given the current case log state.
|
||
3 years ago
|
|
||
|
## Form models and definition
|
||
|
|
||
2 years ago
|
For information about the form model and related models (section, subsection, page, question) and how these relate to each other see [form definition](/form/definition).
|