diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f1befd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/public +/.hugo_build.lock diff --git a/content/docs/Installation.md b/content/docs/Installation.md index 67b1d02..cb641b4 100644 --- a/content/docs/Installation.md +++ b/content/docs/Installation.md @@ -4,4 +4,6 @@ title: Installation weight: 2 --- -# Installation +```golang +go get gitnet.fr/deblan/go-form +``` diff --git a/content/docs/fields/_index.md b/content/docs/fields/_index.md index 677d37e..ae7d331 100644 --- a/content/docs/fields/_index.md +++ b/content/docs/fields/_index.md @@ -1,5 +1,49 @@ --- -linkTitle: Input -title: Input +linkTitle: Fields +title: Fields weight: 3 --- + +The documentation of field is realised with this program. + +```golang {hl_lines=[12,13]} +import ( + "bytes" + "fmt" + "html/template" + + "gitnet.fr/deblan/go-form/form" + "gitnet.fr/deblan/go-form/theme" +) + +func main() { + myForm := form.NewForm( + // the documented field here + // form.NewField... + ). + WithName("form"). + End() + + render := theme.NewRenderer(theme.Html5) + tpl, _ := template.New("example").Funcs(render.FuncMap()).Parse(`{{- form .Form -}}`) + + var buffer bytes.Buffer + + tpl.Execute(&buffer, map[string]any{ + "Form": myForm, + }) + + fmt.Print(buffer.String()) +} +``` + +## Common options + +| Name | type | description | Info | +| ---- | ---- | ---- | ---- | +| `required` | `bool` | Add `required="true"` | Does not apply a constraint | +| `attr` | `map[string]string` | List of extra attributes of the field | | +| `row_attr` | `map[string]string` | List of extra attributes of the field's top container | | +| `label` | `string` | The label of the field | Usually show before the field | +| `label_attr` | `map[string]string` | List of extra attributes of the label | | +| `help` | `string` | Helper of the field | | diff --git a/content/docs/fields/input/_index.md b/content/docs/fields/input/_index.md deleted file mode 100644 index b92c9fb..0000000 --- a/content/docs/fields/input/_index.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -linkTitle: Input -title: Input -weight: 3 ---- - - - - - -
ok
diff --git a/content/docs/fields/input/text.md b/content/docs/fields/input/text.md index f83dd1f..5badb2b 100644 --- a/content/docs/fields/input/text.md +++ b/content/docs/fields/input/text.md @@ -1,10 +1,50 @@ --- linkTitle: Text title: Text +weight: 1 --- - - - - -
ok
+## Basic example + +{{< tabs items="GO,Result" >}} + {{< tab >}} +```golang +form.NewFieldText("Name") +``` + {{< /tab >}} + {{< tab >}} +```html +
+
+ +
+
+``` + {{< /tab >}} +{{< /tabs >}} + +## Fully featured example + +{{< tabs items="GO,Result" >}} + {{< tab >}} +```golang +form.NewFieldText("Name"). + WithOptions( + form.NewOption("label", "Name"), + form.NewOption("required", true), + form.NewOption("attr", map[string]string{"data-foo": "foo"}), + form.NewOption("row_attr", map[string]string{"data-bar": "bar"}), + ) +``` + {{< /tab >}} + {{< tab >}} +```html +
+
+ + +
+
+``` + {{< /tab >}} +{{< /tabs >}} diff --git a/content/docs/form/_index.md b/content/docs/form/_index.md deleted file mode 100644 index e73ab96..0000000 --- a/content/docs/form/_index.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -linkTitle: Form -title: Form -weight: 3 ---- - -A form is a struct containing: - -* Fields -* Options -* Method -* Action - -## Import - -```golang -import ( - "net/http" - - "gitnet.fr/deblan/go-form/form" -) -``` - -## Usage - -```golang -// Let's create a new form -// You can pass *form.Field as arguments -myForm := form.NewForm(field1, field2, ...) - -// Add somes fields -myForm.Add(field3, field4, ...) - -// Set the method -//
-myForm.WithMethod(http.MethodPost) - -// Define the action -// -myForm.WithAction("/") - -// Set a name -myForm.WithName("myForm") - -// Add options -myForm.WithOptions(option1, option2, ...) - -// When all fields are added, call End() -myForm.End() -``` - -## Attributes - -Some options are natively supported in go-form themes. - -```golang -myForm.WithOptions( - form.NewOption("help", "A help for the form"), - // +myForm.WithMethod(http.MethodPost) + +// Define the action +// +myForm.WithAction("/") + +// Set a name +myForm.WithName("myForm") + +// Add options +myForm.WithOptions(option1, option2, ...) + +// When all fields are added, call End() +myForm.End() +``` + +#### Attributes + +Some options are natively supported in go-form themes. + +```golang +myForm.WithOptions( + form.NewOption("help", "A help for the form"), + //