fix html in radio/multiselect options generated id

This commit is contained in:
TEC 2022-10-16 22:54:27 +08:00
parent 780a21b67b
commit 42ec950968
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 4 additions and 4 deletions

View File

@ -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"