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