feat: add data binding

feat: add help
This commit is contained in:
Simon Vieille 2025-07-16 22:37:15 +02:00
commit cef8567ad3
Signed by: deblan
GPG key ID: 579388D585F70417
10 changed files with 140 additions and 44 deletions

View file

@ -9,27 +9,31 @@ func CreateAddressForm() *form.Form {
return form.NewForm(
form.NewFieldText("Name").
WithOptions(
form.Option{Name: "label", Value: "Name"},
form.Option{Name: "required", Value: true},
form.NewOption("label", "Name"),
form.NewOption("required", true),
form.NewOption("help", "A help!"),
).
WithConstraints(
validation.NotBlank{},
),
form.NewSubForm("Address").
WithOptions(form.Option{Name: "label", Value: "Address"}).
WithOptions(form.NewOption("label", "Address")).
Add(
form.NewFieldTextarea("Street").
WithOptions(form.Option{Name: "label", Value: "Street"}).
WithOptions(form.NewOption("label", "Street")).
WithConstraints(
validation.NotBlank{},
),
form.NewFieldText("City").
WithOptions(form.Option{Name: "label", Value: "City"}).
WithOptions(form.NewOption("label", "City")).
WithConstraints(
validation.NotBlank{},
),
form.NewFieldNumber("ZipCode").
WithOptions(form.Option{Name: "label", Value: "Zip code"}).
WithOptions(
form.NewOption("label", "Zip code"),
form.NewOption("help", "A field help"),
).
WithConstraints(
validation.NotBlank{},
),
@ -41,8 +45,9 @@ func CreateAddressForm() *form.Form {
// WithMethod("GET").
WithAction("/").
WithOptions(
form.Option{Name: "attr", Value: map[string]string{
form.NewOption("attr", map[string]string{
"id": "my-form",
}},
}),
form.NewOption("help", "A form help!"),
)
}