From b9fe560b8e6e4d20dcf2b7868791e6e32d5eb98b Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 4 Dec 2023 15:59:26 +0000 Subject: [PATCH] Fix dates and refactor --- .../conditional_question_controller.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/frontend/controllers/conditional_question_controller.js b/app/frontend/controllers/conditional_question_controller.js index a4adfb8ba..30402d471 100644 --- a/app/frontend/controllers/conditional_question_controller.js +++ b/app/frontend/controllers/conditional_question_controller.js @@ -14,28 +14,28 @@ export default class extends Controller { Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => { if (!conditions.map(String).includes(String(selectedValue))) { - let textNumericInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field`) - if (textNumericInput == null) { - textNumericInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field-error`) - } - if (textNumericInput == null) { - const dateInputs = [1, 2, 3].map((idx) => { - return document.getElementById(`${type.replaceAll('-', '_')}_${targetQuestion}_${idx}i`) - }) - this.clearDateInputs(dateInputs) - } else { - this.clearTextNumericInput(textNumericInput) - } + const textNumericInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field`) + const errorInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field-error`) + const dateInputs = [1, 2, 3].map((idx) => { + return document.getElementById(`lettings_log_mrcdate_${idx}i`) + }) + this.clearTextInput(textNumericInput) + this.clearTextInput(errorInput) + this.clearDateInputs(dateInputs) } }) } } - clearTextNumericInput (input) { - input.value = '' + clearTextInput (input) { + if (input != null) { + input.value = '' + } } clearDateInputs (inputs) { - inputs.forEach((input) => { input.value = '' }) + inputs.forEach((input) => { + this.clearTextInput(input) + }) } }