@ -160,6 +157,19 @@ Assumptions made by the format:
- Radio question answer option selected matches one of conditional e.g. ["answer-options-1-string", "answer-option-3-string"]
- Radio question answer option selected matches one of conditional e.g. ["answer-options-1-string", "answer-option-3-string"]
- Numeric question value matches condition e.g. [">2"], ["<7"]or["==6"]
- Numeric question value matches condition e.g. [">2"], ["<7"]or["==6"]
Page routing:
- Form navigation works by stepping sequentially through every page defined in the JSON form definition for the given subsection. For every page it checks if it has "depends_on" conditions. If it does, it evaluates them to determine whether that page should be show or not.
- In this way we can build up whole branches by having:
if(record.armed_forces=="Yes - a regular"||record.armed_forces=="Yes - a reserve")&&record.reservist.blank?
if(record.armedforces=="A current or former regular in the UK Armed Forces (exc. National Service)"||record.armedforces=="A current or former reserve in the UK Armed Forces (exc. National Service)")&&record.reservist.blank?
record.errors.add:reservist,"You must answer the armed forces injury question if the tenant has served in the armed forces"
record.errors.add:reservist,"You must answer the armed forces injury question if the tenant has served in the armed forces"
end
end
if(record.armed_forces=="No"||record.armed_forces=="Prefer not to say")&&record.reservist.present?
if(record.armedforces=="No"||record.armedforces=="Prefer not to say")&&record.reservist.present?
record.errors.add:reservist,"You must not answer the armed forces injury question if the tenant has not served in the armed forces or prefer not to say was chosen"
record.errors.add:reservist,"You must not answer the armed forces injury question if the tenant has not served in the armed forces or prefer not to say was chosen"
end
end
end
end
defvalidate_armed_forces_active_response(record)
defvalidate_armed_forces_active_response(record)
ifrecord.armed_forces=="Yes - a regular"&&record.leftreg.blank?
ifrecord.armedforces=="A current or former regular in the UK Armed Forces (exc. National Service)"&&record.leftreg.blank?
record.errors.add:leftreg,"You must answer the armed forces active question if the tenant has served as a regular in the armed forces"
record.errors.add:leftreg,"You must answer the armed forces active question if the tenant has served as a regular in the armed forces"
end
end
ifrecord.armed_forces!="Yes - a regular"&&record.leftreg.present?
ifrecord.armedforces!="A current or former regular in the UK Armed Forces (exc. National Service)"&&record.leftreg.present?
record.errors.add:leftreg,"You must not answer the armed forces active question if the tenant has not served as a regular in the armed forces"
record.errors.add:leftreg,"You must not answer the armed forces active question if the tenant has not served as a regular in the armed forces"
end
end
end
end
defvalidate_household_pregnancy(record)
defvalidate_pregnancy(record)
if(record.preg_occ=="Yes"||record.preg_occ=="Prefer not to say")&&!women_of_child_bearing_age_in_household(record)
if(record.preg_occ=="Yes"||record.preg_occ=="Prefer not to say")&&!women_of_child_bearing_age_in_household(record)
record.errors.add:preg_occ,"You must answer no as there are no female tenants aged 16-50 in the property"
record.errors.add:preg_occ,"You must answer no as there are no female tenants aged 16-50 in the property"
<%= link_to "Share Lettings and Sales for Social Housing in England Data with DLUHC", "/", class: "govuk-header__link govuk-header__link--service-name" %>
There are 2 ways you can think about form (page) routing logic:
1. Based on the answer you give to a page you are navigated to some point in the form, i.e. a "Jump to"
2. Each question is considered sequentially and independently and we evaluate whether it should be shown or not
Our Form Definition DSL takes the second approach. This has a couple of advantages:
- It makes the check answers pattern easier to code as you can ask each page directly: "Have the conditions for you to be shown been met?", with approach 1, you would effectively have to traverse the full route branch to see if a particular page was shown for each page/question which adds complexity.
- It makes it easier to look at the JSON and see at a glance what conditions will show or hide a page, which is closer to how the business logic is discussed and is easier to reason about.