From c976a86982aabc2685a3d6be9c4da5108577dc99 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 3 Sep 2024 16:55:02 +0200 Subject: [PATCH] fix: make sure to compare comparable values in ternary operators Comparing `"null"` (in the HTML) and `null` (in the JS) was returning false. --- umap/static/umap/js/umap.forms.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index 8eb730eb..7061d632 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -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 },