Make stimulus controller failure tolerant

This commit is contained in:
Björn Fromme
2021-09-01 15:29:34 +02:00
parent 2499f2247d
commit eedaeddc4d
@@ -17,8 +17,12 @@ export default class extends Controller {
}
disabledValueChanged() {
this.containerTarget.classList.toggle(this.gridClass, this.disabledValue === false)
let icon = this.disabledValue ? '#icon-grid' : '#icon-block'
this.iconTarget.setAttribute('href', icon)
if (this.hasContainerTarget) {
this.containerTarget.classList.toggle(this.gridClass, this.disabledValue === false)
}
if (this.hasIconTarget) {
let icon = this.disabledValue ? '#icon-grid' : '#icon-block'
this.iconTarget.setAttribute('href', icon)
}
}
}