Browse Source

Fix dates and refactor

pull/2074/head
Kat 2 years ago
parent
commit
b9fe560b8e
  1. 30
      app/frontend/controllers/conditional_question_controller.js

30
app/frontend/controllers/conditional_question_controller.js

@ -14,28 +14,28 @@ export default class extends Controller {
Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => { Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => {
if (!conditions.map(String).includes(String(selectedValue))) { if (!conditions.map(String).includes(String(selectedValue))) {
let textNumericInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field`) const textNumericInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field`)
if (textNumericInput == null) { const errorInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field-error`)
textNumericInput = document.getElementById(`${type}-${targetQuestion.replaceAll('_', '-')}-field-error`) const dateInputs = [1, 2, 3].map((idx) => {
} return document.getElementById(`lettings_log_mrcdate_${idx}i`)
if (textNumericInput == null) { })
const dateInputs = [1, 2, 3].map((idx) => { this.clearTextInput(textNumericInput)
return document.getElementById(`${type.replaceAll('-', '_')}_${targetQuestion}_${idx}i`) this.clearTextInput(errorInput)
}) this.clearDateInputs(dateInputs)
this.clearDateInputs(dateInputs)
} else {
this.clearTextNumericInput(textNumericInput)
}
} }
}) })
} }
} }
clearTextNumericInput (input) { clearTextInput (input) {
input.value = '' if (input != null) {
input.value = ''
}
} }
clearDateInputs (inputs) { clearDateInputs (inputs) {
inputs.forEach((input) => { input.value = '' }) inputs.forEach((input) => {
this.clearTextInput(input)
})
} }
} }

Loading…
Cancel
Save