--- linkTitle: Fields title: Fields weight: 4 --- A field represents a field in a form. ### Checkbox ```golang func NewFieldCheckbox(name string) *Field ``` {{% goplay-field %}}
field := form.NewFieldCheckbox("Foo")
{{% /goplay-field %}}
Generates an input[type=checkbox]
### Choice
```golang
func NewFieldChoice(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldChoice("Foo")
{{% /goplay-field %}}
Generates inputs (checkbox or radio) or selects
### Csrf
```golang
func NewFieldCsrf(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldCsrf("Foo")
{{% /goplay-field %}}
### Date
```golang
func NewFieldDate(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldDate("Foo")
{{% /goplay-field %}}
Generates an input[type=date] with default transformers
### Datetime
```golang
func NewFieldDatetime(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldDatetime("Foo")
{{% /goplay-field %}}
Generates an input[type=datetime] with default transformers
### DatetimeLocal
```golang
func NewFieldDatetimeLocal(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldDatetimeLocal("Foo")
{{% /goplay-field %}}
Generates an input[type=datetime-local] with default transformers
### Hidden
```golang
func NewFieldHidden(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldHidden("Foo")
{{% /goplay-field %}}
Generates an input[type=hidden]
### Mail
```golang
func NewFieldMail(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldMail("Foo")
{{% /goplay-field %}}
Generates an input[type=email]
### Number
```golang
func NewFieldNumber(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldNumber("Foo")
{{% /goplay-field %}}
Generates an input[type=number] with default transformers
### Password
```golang
func NewFieldPassword(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldPassword("Foo")
{{% /goplay-field %}}
Generates an input[type=password]
### Range
```golang
func NewFieldRange(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldRange("Foo")
{{% /goplay-field %}}
Generates an input[type=range]
### Sub Form
```golang
func NewFieldSubForm(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldSubForm("Foo")
{{% /goplay-field %}}
Alias:
```golang
func NewSubForm(name string) *Field
```
Generates a sub form
### Text
```golang
func NewFieldText(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldText("Foo")
{{% /goplay-field %}}
Generates an input[type=text]
### Textarea
```golang
func NewFieldTextarea(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldTextarea("Foo")
{{% /goplay-field %}}
Generates a textarea
### Time
```golang
func NewFieldTime(name string) *Field
```
{{% goplay-field %}}
field := form.NewFieldTime("Foo")
{{% /goplay-field %}}
Generates an input[type=time] with default transformers
### Submit
```golang
func NewSubmit(name string) *Field
```
{{% goplay-field %}}
field := form.NewSubmit("Foo")
{{% /goplay-field %}}
Generates an input[type=submit]
## Methods
### Add
```golang
func (f *Field) Add(children ...*Field) *Field
```
Appends children
### Bind
```golang
func (f *Field) Bind(data map[string]any, key *string) error
```
Bind the data into the given map
### GetChild
```golang
func (f *Field) GetChild(name string) *Field
```
Returns a child using its name
### GetId
```golang
func (f *Field) GetId() string
```
Computes the id of the field
### GetName
```golang
func (f *Field) GetName() string
```
Computes the name of the field
### GetOption
```golang
func (f *Field) GetOption(name string) *Option
```
Returns an option using its name
### HasChild
```golang
func (f *Field) HasChild(name string) bool
```
Checks if the field contains a child using its name
### HasOption
```golang
func (f *Field) HasOption(name string) bool
```
Checks if the field contains an option using its name
### Mount
```golang
func (f *Field) Mount(data any) error
```
Populates the field with data
### ResetErrors
```golang
func (f *Field) ResetErrors() *Field
```
Resets the field errors
### WithBeforeBind
```golang
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
```golang
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
```golang
func (f *Field) WithConstraints(constraints ...validation.Constraint) *Field
```
Appends constraints
### WithData
```golang
func (f *Field) WithData(data any) *Field
```
Sets data the field
### WithFixedName
```golang
func (f *Field) WithFixedName() *Field
```
Sets that the name of the field is not computed
### WithOptions
```golang
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
```golang
func (f *Field) WithSlice() *Field
```
Sets that the field represents a data slice