Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

mdform source pure

Readme View source

Markdown Form Package

The package provides a very simplistic Gno-Flavored Markdown form generator.

Forms can be created by sequentially calling form methods to create each one of the form fields.

Example usage:

 1import "gno.land/p/jeronimoalbi/mdform"
 2
 3func Render(string) string {
 4    form := mdform.New()
 5
 6    // Add a text input field
 7    form.Input(
 8        "name",
 9        "placeholder", "Name",
10        "value", "John Doe",
11    )
12
13    // Add a select field with three possible values
14    form.Select(
15        "country",
16        "United States",
17        "description", "Select your country",
18    )
19    form.Select(
20        "country",
21        "Spain",
22    )
23    form.Select(
24        "country",
25        "Germany",
26    )
27
28    // Add a checkbox group with two possible values
29    form.Checkbox(
30        "interests",
31        "music",
32        "description", "What do you like to do?",
33    )
34    form.Checkbox(
35        "interests",
36        "tech",
37        "checked", "true",
38    )
39
40    return form.String()
41}

Form output:

1<gno-form exec="FunctionName">
2    <gno-input name="name" placeholder="Name" value="John Doe" />
3    <gno-select name="country" value="United States" description="Select your country" />
4    <gno-select name="country" value="Spain" />
5    <gno-select name="country" value="Germany" />
6    <gno-input type="checkbox" name="interests" value="music" description="What do you like to do?" />
7    <gno-input type="checkbox" name="interests" value="tech" checked="true" />
8</gno-form>

Constants 1

Functions 1

func New

1func New(attributes ...string) *Form
source

New creates a new form.

Types 1

type Form

struct
1type Form struct {
2	attrs  []string
3	fields []string
4}
source

Form is a form that can be rendered to Gno-Flavored Markdown.

Methods on Form

func Checkbox

method on Form
1func (f *Form) Checkbox(name, value string, attributes ...string) *Form
source

Checkbox appends a new input of type checkbox to form fields. Method panics when attributes are not valid.

func Input

method on Form
1func (f *Form) Input(name string, attributes ...string) *Form
source

Input appends a new input to form fields. Use `Form.Radio()` or `Form.Checkbox()` to append those types of inputs to the form. Method panics when appending inputs of type radio or checkbox, or when attributes are not valid.

func Radio

method on Form
1func (f *Form) Radio(name, value string, attributes ...string) *Form
source

Radio appends a new input of type radio to form fields. Method panics when attributes are not valid.

func Select

method on Form
1func (f *Form) Select(name, value string, attributes ...string) *Form
source

Select appends a new select to form fields. Method panics when attributes are not valid.

func String

method on Form
1func (f Form) String() string
source

String returns the form as Gno-Flavored Markdown.

func Textarea

method on Form
1func (f *Form) Textarea(name string, attributes ...string) *Form
source

Textarea appends a new textarea to form fields. Method panics when attributes are not valid.

Imports 2

  • html stdlib
  • strings stdlib

Source Files 5