Migrate from templates to Gomponents (#103)
This commit is contained in:
parent
0bf9ab7189
commit
051d032038
104 changed files with 2768 additions and 2824 deletions
|
|
@ -5,7 +5,7 @@ import (
|
|||
"github.com/mikestefanello/pagoda/pkg/context"
|
||||
)
|
||||
|
||||
// Form represents a form that can be submitted and validated
|
||||
// Form represents a form that can be submitted and validated.
|
||||
type Form interface {
|
||||
// Submit marks the form as submitted, stores a pointer to it in the context, binds the request
|
||||
// values to the struct fields, and validates the input based on the struct tags.
|
||||
|
|
@ -13,29 +13,26 @@ type Form interface {
|
|||
// Returns an echo.HTTPError if the request failed to process.
|
||||
Submit(c echo.Context, form any) error
|
||||
|
||||
// IsSubmitted returns true if the form was submitted
|
||||
// IsSubmitted returns true if the form was submitted.
|
||||
IsSubmitted() bool
|
||||
|
||||
// IsValid returns true if the form has no validation errors
|
||||
// IsValid returns true if the form has no validation errors.
|
||||
IsValid() bool
|
||||
|
||||
// IsDone returns true if the form was submitted and has no validation errors
|
||||
// IsDone returns true if the form was submitted and has no validation errors.
|
||||
IsDone() bool
|
||||
|
||||
// FieldHasErrors returns true if a given struct field has validation errors
|
||||
// FieldHasErrors returns true if a given struct field has validation errors.
|
||||
FieldHasErrors(fieldName string) bool
|
||||
|
||||
// SetFieldError sets a validation error message for a given struct field
|
||||
// SetFieldError sets a validation error message for a given struct field.
|
||||
SetFieldError(fieldName string, message string)
|
||||
|
||||
// GetFieldErrors returns the validation errors for a given struct field
|
||||
// GetFieldErrors returns the validation errors for a given struct field.
|
||||
GetFieldErrors(fieldName string) []string
|
||||
|
||||
// GetFieldStatusClass returns a CSS class to be used for a given struct field
|
||||
GetFieldStatusClass(fieldName string) string
|
||||
}
|
||||
|
||||
// Get gets a form from the context or initializes a new copy if one is not set
|
||||
// Get gets a form from the context or initializes a new copy if one is not set.
|
||||
func Get[T any](ctx echo.Context) *T {
|
||||
if v := ctx.Get(context.FormKey); v != nil {
|
||||
return v.(*T)
|
||||
|
|
@ -44,13 +41,13 @@ func Get[T any](ctx echo.Context) *T {
|
|||
return &v
|
||||
}
|
||||
|
||||
// Clear removes the form set in the context
|
||||
// Clear removes the form set in the context.
|
||||
func Clear(ctx echo.Context) {
|
||||
ctx.Set(context.FormKey, nil)
|
||||
}
|
||||
|
||||
// Submit submits a form
|
||||
// See Form.Submit()
|
||||
// Submit submits a form.
|
||||
// See Form.Submit().
|
||||
func Submit(ctx echo.Context, form Form) error {
|
||||
return form.Submit(ctx, form)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue