mdform source pure
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>
1
1
1
type Form
structForm is a form that can be rendered to Gno-Flavored Markdown.
Methods on Form
func Checkbox
method on FormCheckbox appends a new input of type checkbox to form fields. Method panics when attributes are not valid.
func Input
method on FormInput 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 FormRadio appends a new input of type radio to form fields. Method panics when attributes are not valid.
func Select
method on FormSelect appends a new select to form fields. Method panics when attributes are not valid.
func String
method on FormString returns the form as Gno-Flavored Markdown.
func Textarea
method on FormTextarea appends a new textarea to form fields. Method panics when attributes are not valid.
2
- html stdlib
- strings stdlib