diff --git a/app/webpacker/controllers/conditional_question_controller.js b/app/webpacker/controllers/conditional_question_controller.js index 543e6c512..aab48a280 100644 --- a/app/webpacker/controllers/conditional_question_controller.js +++ b/app/webpacker/controllers/conditional_question_controller.js @@ -10,7 +10,7 @@ export default class extends Controller { let selectedValue = this.element.value let conditional_for = JSON.parse(this.element.dataset.info) Object.entries(conditional_for).map(([targetQuestion, conditions]) => { - if(conditions.includes(selectedValue)) { + if(conditions.map(String).includes(String(selectedValue))) { } else { const textNumericInput = document.getElementById(`case-log-${targetQuestion.replaceAll("_","-")}-field`) if (textNumericInput == null) { diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index 92a2774e8..051bf5862 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -35,4 +35,12 @@ RSpec.describe "Form Conditional Questions" do expect(page).to have_field("case-log-leftreg-field", with: "") end end + + context "when a conditional question has a saved answer", js: true do + it "is displayed correctly" do + case_log.update!(postcode_known: 1, property_postcode: "NW1 6RT") + visit("/logs/#{id}/property-postcode") + expect(page).to have_field("case-log-property-postcode-field", with: "NW1 6RT") + end + end end diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index a943de777..3c17a703e 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -365,6 +365,26 @@ "header": "", "description": "", "questions": { + "postcode_known": { + "check_answer_label": "Do you know the property postcode?", + "header": "Do you know the property’s postcode?", + "hint_text": "", + "type": "radio", + "answer_options": { + "1": { + "value": "Yes" + }, + "0": { + "value": "No" + } + }, + "conditional_for": { + "property_postcode": [ + 1 + ] + }, + "hidden_in_check_answers": true + }, "property_postcode": { "check_answer_label": "Postcode", "header": "", @@ -541,7 +561,7 @@ "depends_on": [{ "net_income_soft_validation_triggered?": true }], "title_text": "Net income is outside the expected range based on the main tenant’s working situation", "informative_text": { - "translation": "soft_validations.net_income.hint_text", + "translation": "soft_validations.net_income.hint_text", "argument": ["ecstat1", "earnings"] }, "questions": { @@ -830,9 +850,9 @@ } } }, - "property_postcode": { + "other_postcode": { "questions": { - "property_postcode": { + "other_postcode": { "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",