Fyne API "widget.Form"

widget.Form


import "fyne.io/fyne/v2/widget"

Usage

type Form

type Form struct {
	BaseWidget

	Items      []*FormItem
	OnSubmit   func() `json:"-"`
	OnCancel   func() `json:"-"`
	SubmitText string
	CancelText string

	// Orientation allows a form to be vertical (a single column), horizontal (default, label then input)
	// or to adapt according to the orientation of the mobile device (adaptive).
	//
	// Since: 2.5
	Orientation Orientation
}

Form widget is two column grid where each row has a label and a widget (usually an input). The last row of the grid will contain the appropriate form control buttons if any should be shown. Setting OnSubmit will set the submit button to be visible and call back the function when tapped. Setting OnCancel will do the same for a cancel button. If you change OnSubmit/OnCancel after the form is created and rendered, you need to call Refresh() to update the form with the correct buttons. Setting OnSubmit/OnCancel to nil will remove the buttons.

func NewForm

func NewForm(items ...*FormItem) *Form

NewForm creates a new form widget with the specified rows of form items and (if any of them should be shown) a form controls row at the bottom

func (*Form) Append

func (f *Form) Append(text string, widget fyne.CanvasObject)

Append adds a new row to the form, using the text as a label next to the specified Widget

func (*Form) AppendItem

func (f *Form) AppendItem(item *FormItem)

AppendItem adds the specified row to the end of the Form

func (*Form) CreateRenderer

func (f *Form) CreateRenderer() fyne.WidgetRenderer

CreateRenderer is a private method to Fyne which links this widget to its renderer

func (*Form) Disable

func (f *Form) Disable()

Disable disables submitting this form.

Since: 2.1

func (*Form) Disabled

func (f *Form) Disabled() bool

Disabled returns whether submitting the form is disabled. Note that, if the form fails validation, the submit button may be disabled even if this method returns true.

Since: 2.1

func (*Form) Enable

func (f *Form) Enable()

Enable enables submitting this form.

Since: 2.1

func (*Form) MinSize

func (f *Form) MinSize() fyne.Size

MinSize returns the size that this widget should not shrink below

func (*Form) Refresh

func (f *Form) Refresh()

Refresh updates the widget state when requested.

func (*Form) SetOnValidationChanged

func (f *Form) SetOnValidationChanged(callback func(error))

SetOnValidationChanged is intended for parent widgets or containers to hook into the validation. The function might be overwritten by a parent that cares about child validation (e.g. widget.Form)

func (*Form) Validate

func (f *Form) Validate() error

Validate validates the entire form and returns the first error that is encountered.