diff --git a/content/docs/fields/_index.md b/content/docs/fields/_index.md index c516e89..88dc12e 100644 --- a/content/docs/fields/_index.md +++ b/content/docs/fields/_index.md @@ -11,36 +11,10 @@ A field represents a field in a form. ```golang func NewFieldCheckbox(name string) *Field ``` -{{% goplay %}} - - -{{% /goplay %}} +{{% gpfield %}} + +{{% /gpfield %}} Generates an input[type=checkbox] @@ -50,36 +24,11 @@ Generates an input[type=checkbox] func NewFieldChoice(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates inputs (checkbox or radio) or selects @@ -90,36 +39,13 @@ Generates inputs (checkbox or radio) or selects func NewFieldCsrf(name string) *Field ``` -{{% goplay %}} - +{{% details title="Test me" closed="true" %}} +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} +{{% /details %}} ### Date @@ -127,36 +53,11 @@ func r(f *form.Form) { func NewFieldDate(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=date] with default transformers @@ -166,36 +67,11 @@ Generates an input[type=date] with default transformers func NewFieldDatetime(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=datetime] with default transformers @@ -205,36 +81,11 @@ Generates an input[type=datetime] with default transformers func NewFieldDatetimeLocal(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=datetime-local] with default transformers @@ -244,36 +95,11 @@ Generates an input[type=datetime-local] with default transformers func NewFieldHidden(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=hidden] @@ -283,36 +109,11 @@ Generates an input[type=hidden] func NewFieldMail(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=email] @@ -322,36 +123,11 @@ Generates an input[type=email] func NewFieldNumber(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=number] with default transformers @@ -361,36 +137,11 @@ Generates an input[type=number] with default transformers func NewFieldPassword(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=password] @@ -400,36 +151,11 @@ Generates an input[type=password] func NewFieldRange(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=range] @@ -439,36 +165,11 @@ Generates an input[type=range] func NewFieldSubForm(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Alias: @@ -484,36 +185,11 @@ Generates a sub form func NewFieldText(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=text] @@ -523,36 +199,11 @@ Generates an input[type=text] func NewFieldTextarea(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates a textarea @@ -562,36 +213,11 @@ Generates a textarea func NewFieldTime(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=time] with default transformers @@ -601,36 +227,11 @@ Generates an input[type=time] with default transformers func NewSubmit(name string) *Field ``` -{{% goplay %}} - +{{% gpfield %}} - -{{% /goplay %}} +{{% /gpfield %}} Generates an input[type=submit] diff --git a/content/docs/rendering/_index.md b/content/docs/rendering/_index.md index d3454a6..4651543 100644 --- a/content/docs/rendering/_index.md +++ b/content/docs/rendering/_index.md @@ -8,27 +8,30 @@ weight: 6 Here is a simple example that displays a form: ```golang -http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - myForm := form.NewForm(...) +myForm := form.NewForm(...) - render := theme.NewRenderer(theme.Html5) - tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(` - - - My form - - - {{ form .Form }} - - - `) +render := theme.NewRenderer(theme.Html5) +tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(` + + + My form + + + {{ form .Form }} + + +`) - w.Header().Set("Content-Type", "text/html; charset=utf-8") +tpl.Execute(w, map[string]any{ + "Form": myForm, +}) - tpl.Execute(w, map[string]any{ - "Form": myForm, - }) -} +tpl, _ := template.New("example").Funcs(render.FuncMap()).Parse("{{ form_widget .Form }}") + +b := new(strings.Builder) +tpl.Execute(b, map[string]any{"Form": f}) + +fmt.Println(b.String()) ``` Other helper functions are available to render specific parts of the form: diff --git a/layouts/shortcodes/gpfield.html b/layouts/shortcodes/gpfield.html new file mode 100644 index 0000000..e16ae20 --- /dev/null +++ b/layouts/shortcodes/gpfield.html @@ -0,0 +1,139 @@ +{{ $id := md5 .Inner }} {{ .Inner }} + +
+Test me + +
+
+ + + +
+
+ + + +