Fields

Fields

A field represents a field in a form.

Checkbox

func NewFieldCheckbox(name string) *Field
Test me

Generates an input[type=checkbox]

Choice

func NewFieldChoice(name string) *Field
Test me

Generates inputs (checkbox or radio) or selects

Csrf

func NewFieldCsrf(name string) *Field
Test me

Date

func NewFieldDate(name string) *Field
Test me

Generates an input[type=date] with default transformers

Datetime

func NewFieldDatetime(name string) *Field
Test me

Generates an input[type=datetime] with default transformers

DatetimeLocal

func NewFieldDatetimeLocal(name string) *Field
Test me

Generates an input[type=datetime-local] with default transformers

Hidden

func NewFieldHidden(name string) *Field
Test me

Generates an input[type=hidden]

Mail

func NewFieldMail(name string) *Field
Test me

Generates an input[type=email]

Number

func NewFieldNumber(name string) *Field
Test me

Generates an input[type=number] with default transformers

Password

func NewFieldPassword(name string) *Field
Test me

Generates an input[type=password]

Range

func NewFieldRange(name string) *Field
Test me

Generates an input[type=range]

Sub Form

func NewFieldSubForm(name string) *Field
Test me

Alias:

func NewSubForm(name string) *Field

Generates a sub form

Text

func NewFieldText(name string) *Field
Test me

Generates an input[type=text]

Textarea

func NewFieldTextarea(name string) *Field
Test me

Generates a textarea

Time

func NewFieldTime(name string) *Field
Test me

Generates an input[type=time] with default transformers

Submit

func NewSubmit(name string) *Field
Test me

Generates an input[type=submit]

Methods

Add

func (f *Field) Add(children ...*Field) *Field

Appends children

Bind

func (f *Field) Bind(data map[string]any, key *string) error

Bind the data into the given map

GetChild

func (f *Field) GetChild(name string) *Field

Returns a child using its name

GetId

func (f *Field) GetId() string

Computes the id of the field

GetName

func (f *Field) GetName() string

Computes the name of the field

GetOption

func (f *Field) GetOption(name string) *Option

Returns an option using its name

HasChild

func (f *Field) HasChild(name string) bool

Checks if the field contains a child using its name

HasOption

func (f *Field) HasOption(name string) bool

Checks if the field contains an option using its name

Mount

func (f *Field) Mount(data any) error

Populates the field with data

ResetErrors

func (f *Field) ResetErrors() *Field

Resets the field errors

WithBeforeBind

func (f *Field) WithBeforeBind(callback func(data any) (any, error)) *Field

Sets a transformer applied to the data of a field before defining it in a structure

WithBeforeMount

func (f *Field) WithBeforeMount(callback func(data any) (any, error)) *Field

Sets a transformer applied to the structure data before displaying it in a field

WithConstraints

func (f *Field) WithConstraints(constraints ...validation.Constraint) *Field

Appends constraints

WithData

func (f *Field) WithData(data any) *Field

Sets data the field

WithFixedName

func (f *Field) WithFixedName() *Field

Sets that the name of the field is not computed

WithOptions

func (f *Field) WithOptions(options ...*Option) *Field

Common options

Name type description Info
required bool Add required="true" Does not apply a constraint
attr form.Attrs List of extra attributes of the field
row_attr form.Attrs List of extra attributes of the field’s top container
label string The label of the field Usually show before the field
label_attr form.Attrs List of extra attributes of the label
help string Helper of the field
help_attr form.Attrs List of extra attributes of the help

Appends options to the field

WithSlice

func (f *Field) WithSlice() *Field

Sets that the field represents a data slice