From 5e4fbfdf1928682bb0411badcc78949dae29476c Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 27 Jun 2022 17:37:09 +0100 Subject: [PATCH] Init form runner --- docs/form_builder.md | 4 ++-- docs/form_runner.md | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/form_builder.md b/docs/form_builder.md index a61497a19..74fcef644 100644 --- a/docs/form_builder.md +++ b/docs/form_builder.md @@ -30,7 +30,7 @@ As a result it's not modelled as part of the config but rather as code. It still ### Features the Form Config supports - Defining sections, subsections, pages and questions that fit the GovUK tasklist pattern -- Text, Numeric, Radio, Select and Checkbox question types +- Text, Numeric, Date, Radio, Select and Checkbox question types - Conditional questions (`conditional_for`) - Radio and Checkbox questions can support "conditional" text or numeric questions that show/hide on the same page when the triggering option is selected - Routing (`depends_on`) - all pages can specify conditions (attributes of the case log) that determine whether or not they're shown to the user - Methods can be chained (i.e. you can have conditions in the form `{ owning_organisation.provider_type: "local_authority"`) which will call `case_log.owning_organisation.provider_type` and compare the result to the provided value. @@ -38,7 +38,7 @@ As a result it's not modelled as part of the config but rather as code. It still - By default questions on pages that are not routed to are assumed to be invalid and are cleared. This can be prevented by setting `derived: true` on a question. - Questions can be optionally hidden from the check answers page of each section by setting `hidden_in_check_answers: true`. This can also take a condition. - Questions can be set as being inferred from other answers. This is similar to derived with the difference being that derived questions can be derived from anything not just other form question answers, and inferred answers are cleared when the answers they depend on change, whereas derived questions aren't. -- Soft validation interruption pages can be included +- Soft validation interruption pages can be included - For complex html guidance partials can be referenced ### JSON Config diff --git a/docs/form_runner.md b/docs/form_runner.md index e69de29bb..faf46556d 100644 --- a/docs/form_runner.md +++ b/docs/form_runner.md @@ -0,0 +1,19 @@ +# Form Runner + +The form runner is composed of: + +Ruby Classes: +- 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`) +- Section, Subsection, Page and Question classes (`app/models/form/`) +- Setup subsection specific instances (subclasses) of Section, Subsection, Pages and Questions (`app/form/setup/`) + +ERB Templates: +- 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`) + +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` + +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.