Skip to content

Add form validation#6323

Draft
andydotxyz wants to merge 9 commits into
fyne-io:developfrom
andydotxyz:feature/formvalidate
Draft

Add form validation#6323
andydotxyz wants to merge 9 commits into
fyne-io:developfrom
andydotxyz:feature/formvalidate

Conversation

@andydotxyz
Copy link
Copy Markdown
Member

@andydotxyz andydotxyz commented May 28, 2026

Adding Form.Validator to check the whole of a form and control if Submit is enabled.
(this is built on top of FormItem.Required to avoid conflicts)

Tests still to be included (- and balance the old entry validation specifics with this), PR is open for feedback just now, try this code:

// Package main loads a very basic Hello World graphical application.
package main

import (
	"errors"

	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Hello")

	en1 := widget.NewEntry()
	en2 := widget.NewEntry()
	en2.Validator = func(in string) error {
		if in != "hi" {
			return errors.New("must be hi")
		}
		return nil
	}

	f := widget.NewForm(
		widget.NewFormItem("1", en1),
		widget.NewFormItem("2", en2))
	f.Validator = func() error {
		if en1.Text != en2.Text {
			return errors.New("en1 != en2")
		}
		return nil
	}
	f.OnSubmit = func() {}
	w.SetContent(f)

	w.ShowAndRun()
}

Fixes #2562

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.
  • Public APIs match existing style and have Since: line.

@andydotxyz andydotxyz force-pushed the feature/formvalidate branch from a49c3a3 to 9d1a0a3 Compare May 28, 2026 21:27
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 60.442% (+0.04%) from 60.406% — andydotxyz:feature/formvalidate into fyne-io:develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form validator

2 participants