Browse Source

Fix conditional field clearing condition (#389)

pull/390/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
bace6dd695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/webpacker/controllers/conditional_question_controller.js
  2. 8
      spec/features/form/conditional_questions_spec.rb
  3. 24
      spec/fixtures/forms/2021_2022.json

2
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) {

8
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

24
spec/fixtures/forms/2021_2022.json vendored

@ -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": "",
@ -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",

Loading…
Cancel
Save