Browse Source

Clear conditional date fields if invalidated by top level answer

pull/235/head
baarkerlounger 3 years ago
parent
commit
7f23f34b14
  1. 19
      app/webpacker/controllers/conditional_question_controller.js

19
app/webpacker/controllers/conditional_question_controller.js

@ -16,15 +16,30 @@ export default class extends Controller {
} }
} }
clearTextNumericInput(input) {
input.value = ""
}
clearDateInputs(inputs) {
inputs.forEach((input) => { input.value = "" })
}
displayConditionalRadio() { displayConditionalRadio() {
if(this.element.checked) { if(this.element.checked) {
let selectedValue = this.element.value let selectedValue = this.element.value
let conditional_for = JSON.parse(this.element.dataset.info) let conditional_for = JSON.parse(this.element.dataset.info)
Object.entries(conditional_for).map(([targetQuestion, conditions]) => { Object.entries(conditional_for).map(([targetQuestion, conditions]) => {
let input = document.getElementById(`case-log-${targetQuestion.replaceAll("_","-")}-field`)
if(conditions.includes(selectedValue)) { if(conditions.includes(selectedValue)) {
} else { } else {
input.value = "" const textNumericInput = document.getElementById(`case-log-${targetQuestion.replaceAll("_","-")}-field`)
if (textNumericInput == null) {
const dateInputs = [1,2,3].map((idx) => {
return document.getElementById(`case_log_${targetQuestion}_${idx}i`)
})
this.clearDateInputs(dateInputs)
} else {
this.clearTextNumericInput(textNumericInput)
}
} }
}) })
} }

Loading…
Cancel
Save