forms

package
v0.0.0-...-388a9ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrValidationFailed = errors.Errorf("Form validation failed")

Functions

func DefaultHandler

func DefaultHandler(c *gin.Context, db *sqlx.DB, form Form)

func FormSaveFullReload

func FormSaveFullReload(c *gin.Context, f Form)

Types

type Form

type Form interface {
	FormName() string
	ClearInput()
	ShouldBind(c *gin.Context) error
	RenderForm(c *gin.Context)
	SetFormError(message string)
	AddError(fieldName string, message string)
	Save(c context.Context, exec boil.ContextExecutor) (FormSaveAction, error)
	AddTemplateData(field string, value any)
	TemplateData() map[string]interface{}

	// the only thing to implement in the child form
	Validate(c *gin.Context, exec boil.ContextExecutor) error
}

type FormBase

type FormBase[T any] struct {
	Name                 string
	FormTemplate         string
	FormSaved            bool
	KeepValuesAfterSave  bool
	FullPageReloadOnSave bool

	// we make no effort to sync the keys names between
	// errors and struct, we just assume it to be matching.
	// Same goes for the templates - it's completely left
	// to the developer
	Errors            FormErrors
	FormError         string
	Input             *T
	ExtraTemplateData map[string]interface{}
}

func (*FormBase[T]) AddError

func (f *FormBase[T]) AddError(fieldName string, message string)

func (*FormBase[T]) AddTemplateData

func (f *FormBase[T]) AddTemplateData(field string, value any)

func (*FormBase[T]) ClearInput

func (f *FormBase[T]) ClearInput()

func (*FormBase[T]) FormName

func (f *FormBase[T]) FormName() string

func (*FormBase[T]) RenderForm

func (f *FormBase[T]) RenderForm(c *gin.Context)

func (*FormBase[T]) Save

func (*FormBase[T]) SetFormError

func (f *FormBase[T]) SetFormError(message string)

func (*FormBase[T]) ShouldBind

func (f *FormBase[T]) ShouldBind(c *gin.Context) error

func (*FormBase[T]) TemplateData

func (f *FormBase[T]) TemplateData() map[string]interface{}

type FormErrors

type FormErrors map[string]string

func (FormErrors) HasError

func (fe FormErrors) HasError(fieldName string) bool

func (FormErrors) PassedValidation

func (fe FormErrors) PassedValidation() error

type FormSaveAction

type FormSaveAction func(*gin.Context, Form)

func FormSaveDefault

func FormSaveDefault(keepValues bool) FormSaveAction

func FormSaveRedirect

func FormSaveRedirect(url string) FormSaveAction

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL