From 42ec9509680408591261b5000862556635b0de7d Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 16 Oct 2022 22:54:27 +0800 Subject: [PATCH] fix html in radio/multiselect options generated id --- lib/Surveys.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Surveys.jl b/lib/Surveys.jl index abc8969..1a35e0c 100644 --- a/lib/Surveys.jl +++ b/lib/Surveys.jl @@ -564,13 +564,13 @@ function htmlrender(q::Union{<:Question{RadioSelect}, Question{MultiSelect}}, if nonempty in q.validators "true" else false end), '\n', join(map(q.field.options.options |> enumerate) do (i, opt) - id = string("qn-", q.id, "-", opt.second) + id = string("qn-", q.id, "-", replace(opt.second, r"[^A-Za-z0-9]+" => '-')) elem("label", elem("input", :type => type, :id => id, :name => string(q.id, "[]"), :value => html_escape(opt.second), :checked => (!ismissing(value) && opt.second ∈ value), if type == "radio" && q.field.other - [:oninput => "document.getElementById('$(string("qn-", q.id, "--other-input"))').value = ''"] + [:oninput => "document.getElementById('$(string("qn-", q.id, "---other-input"))').value = ''"] else [] end...) * opt.first, :for => id) @@ -588,10 +588,10 @@ function htmlrender(q::Union{<:Question{RadioSelect}, Question{MultiSelect}}, :id => string("qn-", q.id, "--other"), :value => "", :checked => length(othervals) > 0, if type == "checkbox" - [:oninput => "if (!this.checked) { document.getElementById('$(string("qn-", q.id, "--other-input"))').value = '' }"] + [:oninput => "if (!this.checked) { document.getElementById('$(string("qn-", q.id, "---other-input"))').value = '' }"] else [] end...), elem("input", :type => "text", - :id => string("qn-", q.id, "--other-input"), + :id => string("qn-", q.id, "---other-input"), :class => "other", :placeholder => "Other", :name => string(q.id, "[]"), :value => html_escape(join(othervals, ", ")), :oninput => "document.getElementById('$(string("qn-", q.id, "--other"))').checked = this.value.length > 0"