You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
3 years ago
|
import { Controller } from "@hotwired/stimulus"
|
||
|
|
||
|
export default class extends Controller {
|
||
|
initialize() {
|
||
|
this.displayConditional()
|
||
|
}
|
||
|
|
||
|
displayConditional() {
|
||
|
if(this.element.checked) {
|
||
3 years ago
|
let selectedValue = this.element.value
|
||
3 years ago
|
let conditional_for = JSON.parse(this.element.dataset.info)
|
||
3 years ago
|
Object.entries(conditional_for).map(([targetQuestion, conditions]) => {
|
||
3 years ago
|
if(conditions.map(String).includes(String(selectedValue))) {
|
||
3 years ago
|
} else {
|
||
|
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)
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
clearTextNumericInput(input) {
|
||
|
input.value = ""
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
clearDateInputs(inputs) {
|
||
|
inputs.forEach((input) => { input.value = "" })
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|