From a10a52dcb79220677e113f345fe3d1ca50800d48 Mon Sep 17 00:00:00 2001 From: Adriano Caloiaro Date: Thu, 20 Feb 2025 10:28:33 -0700 Subject: [PATCH] fix: single choice elements cannot be optionally required --- ui/common.templ | 10 ++++++++++ ui/common_templ.go | 6 +++--- ui/common_templ.txt | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ui/common.templ b/ui/common.templ index 55eecdb..1442722 100644 --- a/ui/common.templ +++ b/ui/common.templ @@ -100,6 +100,16 @@ templ Head(pageTitle string) { let watchingField = watchingFields[i] let match = false var watcherFieldElement = document.getElementById(watchingField.id) // the actual element watching the field + // radio form elements such as "single choice" elements cannot get gotten by ID because they are + // radio button in a form group, all sharing a "name" attribute, rather than having one unique id + // like other input elements. Thus, when we cannot get a watching field by ID, we must be able to get it by + // name. + if (watcherFieldElement == null) { + radioFormElements = document.getElementsByName(watchingField.id) + if (radioFormElements.length > 0) { + watcherFieldElement = radioFormElements[0] + } + } var watcherFieldContainerID = `field-container-${watchingField.id}` // the DOM element that contains the watching field logic = watchingField.logic diff --git a/ui/common_templ.go b/ui/common_templ.go index 54a9516..744997d 100644 --- a/ui/common_templ.go +++ b/ui/common_templ.go @@ -464,7 +464,7 @@ func Head(pageTitle string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\"> ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\"> ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -623,7 +623,7 @@ func ValidationErrors(errs types.ValidationErrors) templ.Component { var templ_7745c5c3_Var32 string templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("errors-%s", fieldID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 214, Col: 46} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 224, Col: 46} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) if templ_7745c5c3_Err != nil { @@ -636,7 +636,7 @@ func ValidationErrors(errs types.ValidationErrors) templ.Component { var templ_7745c5c3_Var33 string templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(err.Error()) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 216, Col: 18} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/common.templ`, Line: 226, Col: 18} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) if templ_7745c5c3_Err != nil { diff --git a/ui/common_templ.txt b/ui/common_templ.txt index 43272d1..9ce4eb2 100644 --- a/ui/common_templ.txt +++ b/ui/common_templ.txt @@ -25,7 +25,7 @@ \" nonce=\" \" async> +\">