fyne icon indicating copy to clipboard operation
fyne copied to clipboard

Unable to submit form despite validation passing.

Open turtletowerz opened this issue 1 year ago • 7 comments

Checklist

  • [X] I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • [X] This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

When opening a form with a data-binded value, and specifically with regex validation (i have yet to test any other method) the form will occasionally open with a grayed out submit button even if the form input is validated. This behavior only happens when the form is opened, and after re-entering the value the validation fixes and the submit button becomes usable.

How to reproduce

  1. Click "Change value" and change the value in the form to any number
  2. Submit the form
  3. Reopen the change value form and see that the submit button is grayed out even with validation passing (this is not guaranteed to happen on the first try, it seems pretty random)

Screenshots

Example when this code is run, note the grayed out submit despite validation saying all form elements are passing.

Example code

package main

import (
	"errors"
	"regexp"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
)

func makeForm(a fyne.App, bind binding.String) {
	entry := widget.NewEntryWithData(bind)
	re := regexp.MustCompile(`\d+`)
	entry.Validator = func(s string) error {
		if !re.MatchString(s) {
			return errors.New("invalid input")
		}
		return nil
	}

	w := a.NewWindow("Value Changer")
	w.Resize(fyne.NewSize(200, 150))
	w.CenterOnScreen()

	form := widget.NewForm(
		widget.NewFormItem("Value", entry),
	)

	form.OnSubmit = func() {
		w.Close()
	}

	w.SetContent(container.NewVScroll(form))
	w.Show()
}

func main() {
	a := app.New()
	window := a.NewWindow("Bug Test")
	window.Resize(fyne.NewSize(200, 150))
	window.SetFixedSize(true)
	window.CenterOnScreen()
	window.SetMaster()

	var val int
	bind := binding.IntToString(binding.BindInt(&val))

	box := container.NewVBox(
		widget.NewButton("Change Value", func() {
			makeForm(a, bind)
		}),

		widget.NewLabel("Value"),
		widget.NewLabelWithData(bind),
	)

	window.SetContent(box)
	window.ShowAndRun()
}

Fyne version

2.3.5

Go compiler version

1.20.4

Operating system and version

Arch Linux, Kernel 6.3.2

Additional Information

No response

turtletowerz avatar Jun 08 '23 23:06 turtletowerz