summaryrefslogtreecommitdiff
path: root/form/field.templ
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-17 16:37:23 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-17 16:37:23 +0200
commitb2447bc967df37b31282a97e32c581954bb8bcc9 (patch)
tree39758d1121fae6dc1d27e8a45035690421900d6c /form/field.templ
parent789d21034e526a03d3e91d5d284a4888be938340 (diff)
downloadgosten-b2447bc967df37b31282a97e32c581954bb8bcc9.tar.gz
gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.tar.bz2
gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.zip
Move from html/template to templ
Diffstat (limited to 'form/field.templ')
-rw-r--r--form/field.templ42
1 files changed, 42 insertions, 0 deletions
diff --git a/form/field.templ b/form/field.templ
new file mode 100644
index 0000000..e9ce33e
--- /dev/null
+++ b/form/field.templ
@@ -0,0 +1,42 @@
+package form
+
+import "fmt"
+
+func (f *field) isCheckbox() bool {
+ return f.Type == "checkbox"
+}
+
+func (f *field) optionAttributes() templ.Attributes {
+ attrs := make(map[string]any)
+ for _, o := range f.Options {
+ attrs[o] = true
+ }
+ return templ.Attributes(attrs)
+}
+
+templ (f *field) item(errors []string) {
+ <div class={"mb-3",
+ templ.KV("form-floating", !f.isCheckbox()),
+ templ.KV("form-check form-switch", f.isCheckbox())}>
+ <input
+ if f.ID != "" {id={f.ID}}
+ type={f.Type}
+ name={f.Name}
+ placeholder={f.Placeholder}
+ if f.Value != nil {value={fmt.Sprint(f.Value)}}
+ if f.isCheckbox() {
+ class="form-check-input"
+ } else {
+ class="form-control"
+ }
+ {f.optionAttributes()...}
+ >
+ <label if f.ID != "" {for={f.ID}}
+ if f.isCheckbox() {class="form-check-label"}>
+ {f.Label}
+ </label>
+ for _, e := range errors {
+ <p style="color:red">{e}</p>
+ }
+ </div>
+} \ No newline at end of file