fix: make sure to compare comparable values in ternary operators

Comparing `"null"` (in the HTML) and `null` (in the JS) was returning
false.
This commit is contained in:
Yohan Boniface 2024-09-03 16:55:02 +02:00
parent 185cc65f68
commit c976a86982

View file

@ -902,8 +902,8 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
if (!this.container.querySelector(`input[type="radio"][value="${value}"]`)) {
value = this.options.default !== undefined ? this.options.default : this.default
}
const choices = this.getChoices().map(([value, label]) => value)
if (choices.includes(value)) {
const choices = this.getChoices().map(([value, label]) => `${value}`)
if (choices.includes(`${value}`)) {
this.container.querySelector(`input[type="radio"][value="${value}"]`).checked =
true
}
@ -925,8 +925,8 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
`${this.className} by${choices.length}`,
this.parentNode
)
for (let i = 0; i < choices.length; i++) {
this.addChoice(choices[i][0], choices[i][1], i)
for (const [i, [value, label]] of choices.entries()) {
this.addChoice(value, label, i)
}
this.fetch()
},
@ -958,8 +958,12 @@ L.FormBuilder.TernaryChoices = L.FormBuilder.MultiChoice.extend({
case false:
value = false
break
default:
case 'null':
case null:
value = null
break
default:
value = undefined
}
return value
},