dhtmlform

package module
v0.9.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 6 Imported by: 4

README

dhtmlforms - Golang forms handling

Golang forms handling for mitoteam/dhtml.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFormControlHandler

func RegisterFormControlHandler(controlKind string, handler *FormControlHandler)

func Settings

func Settings() *settingsType

Types

type FormContext

type FormContext struct {
	// contains filtered or unexported fields
}

Initial data to build a form

func NewFormContext

func NewFormContext(w http.ResponseWriter, r *http.Request) *FormContext

func (*FormContext) GetArg

func (fc *FormContext) GetArg(key string) any

func (*FormContext) GetParam

func (fc *FormContext) GetParam(key string) any

func (*FormContext) SetArg

func (fc *FormContext) SetArg(key string, v any) *FormContext

func (*FormContext) SetParam

func (fc *FormContext) SetParam(key string, v any) *FormContext

func (*FormContext) SetRedirect

func (fc *FormContext) SetRedirect(url string) *FormContext

type FormControlData

type FormControlData struct {
	Value any
	// contains filtered or unexported fields
}

Form control data to be stored in FormData between builds

func (*FormControlData) GetProp

func (fcd *FormControlData) GetProp(key string) any

func (*FormControlData) HasProp

func (fcd *FormControlData) HasProp(key string) bool

func (*FormControlData) SetProp

func (fcd *FormControlData) SetProp(key string, value any)

type FormControlElement

type FormControlElement struct {
	// contains filtered or unexported fields
}

default implementation of FormControlElementI

func NewCheckbox

func NewCheckbox(name string) *FormControlElement

func NewDateInput

func NewDateInput(name string) *FormControlElement

func NewEmailInput

func NewEmailInput(name string) *FormControlElement

func NewFormControl

func NewFormControl(controlKind string, name string) *FormControlElement

func NewHidden

func NewHidden(name string) *FormControlElement

func NewNumberInput

func NewNumberInput(name string) *FormControlElement

func NewPasswordInput

func NewPasswordInput(name string) *FormControlElement

func NewSubmitBtn

func NewSubmitBtn() *FormControlElement

func NewTelInput

func NewTelInput(name string) *FormControlElement

func NewTextInput

func NewTextInput(name string) *FormControlElement

func NewTextarea

func NewTextarea(name string) *FormControlElement

func NewTimeInput

func NewTimeInput(name string) *FormControlElement

func NewUrlInput

func NewUrlInput(name string) *FormControlElement

func (*FormControlElement) Default

func (e *FormControlElement) Default(v any) *FormControlElement

Sets default control value. Used only for initial form build. Replaced by POST value when re-builds.

func (*FormControlElement) GetControlData

func (e *FormControlElement) GetControlData() *FormControlData

func (*FormControlElement) GetId

func (e *FormControlElement) GetId() string

func (*FormControlElement) GetLabel

func (e *FormControlElement) GetLabel() *dhtml.HtmlPiece

func (*FormControlElement) GetName

func (e *FormControlElement) GetName() string

func (*FormControlElement) GetNote

func (e *FormControlElement) GetNote() *dhtml.HtmlPiece

func (*FormControlElement) GetPlaceholder

func (e *FormControlElement) GetPlaceholder() string

func (*FormControlElement) GetProp

func (e *FormControlElement) GetProp(key string) any

func (*FormControlElement) GetTags

func (e *FormControlElement) GetTags() dhtml.TagList

func (*FormControlElement) GetValue

func (e *FormControlElement) GetValue() any

func (*FormControlElement) HasProp

func (e *FormControlElement) HasProp(key string) bool

func (*FormControlElement) IsError

func (e *FormControlElement) IsError() bool

func (*FormControlElement) IsRequired

func (e *FormControlElement) IsRequired() bool

func (*FormControlElement) Label

func (*FormControlElement) Note

func (*FormControlElement) Placeholder

func (e *FormControlElement) Placeholder(s string) *FormControlElement

func (*FormControlElement) Require

func (e *FormControlElement) Require() *FormControlElement

Shorthand for SetRequired(true)

func (*FormControlElement) SetControlData

func (e *FormControlElement) SetControlData(data *FormControlData)

func (*FormControlElement) SetProp

func (e *FormControlElement) SetProp(key string, value any) *FormControlElement

func (*FormControlElement) SetRequired

func (e *FormControlElement) SetRequired(b bool) *FormControlElement

type FormControlElementI

type FormControlElementI interface {
	dhtml.ElementI

	GetName() string
	GetControlData() *FormControlData
	SetControlData(*FormControlData)
}

type FormControlErrors

type FormControlErrors struct {
	Label  dhtml.HtmlPiece   //form control label to render
	Errors []dhtml.HtmlPiece // errors list
}

type FormControlHandler

type FormControlHandler struct {
	// [required] renders control
	RenderF func(control *FormControlElement) dhtml.HtmlPiece

	// [optional] preprocesses raw data from POST
	ProcessPostValueF func(controlData *FormControlData)
}

func GetFormControlHandler

func GetFormControlHandler(controlKind string) (*FormControlHandler, bool)

type FormData

type FormData struct {
	// contains filtered or unexported fields
}

Represents form state between builds from rendering through validation and submit. Constructed on first render from FormContext, stored on server side. Linked to browser representation by build_id.

func NewFormData

func NewFormData() *FormData

func (*FormData) ClearErrors

func (fd *FormData) ClearErrors()

func (*FormData) GetArg

func (fd *FormData) GetArg(name string) any

func (*FormData) GetControlValue

func (fd *FormData) GetControlValue(name string) any

func (*FormData) GetParam

func (fd *FormData) GetParam(name string) any

func (*FormData) GetRedirect

func (fd *FormData) GetRedirect() string

func (*FormData) GetValue

func (fd *FormData) GetValue(name string) any

Shorthand for GetControlValue(name)

func (*FormData) HasError

func (fd *FormData) HasError() bool

func (*FormData) IsRebuild

func (fd *FormData) IsRebuild() bool

func (*FormData) SetControlValue

func (fd *FormData) SetControlValue(name string, v any) *FormData

func (*FormData) SetError

func (fd *FormData) SetError(controlName string, v any)

func (*FormData) SetParam

func (fd *FormData) SetParam(name string, value any)

func (*FormData) SetRebuild

func (fd *FormData) SetRebuild(v bool)

func (*FormData) SetRedirect

func (fd *FormData) SetRedirect(url string)

type FormErrors

type FormErrors map[string]*FormControlErrors

List of form control errors (name => errors list, empty string name for common errors)

type FormHandler

type FormHandler struct {
	RenderF   func(formBody *dhtml.HtmlPiece, fd *FormData)
	ValidateF func(fd *FormData)
	SubmitF   func(fd *FormData)
}

func (*FormHandler) Render

func (fh *FormHandler) Render(fc *FormContext) *dhtml.HtmlPiece

Jump to

Keyboard shortcuts

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