You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you create a form and put in an entry with data, set a custom validator and change the data after you set the content of the window the entry will display an error even though the content is correct according to the validator and you won't be to submit the form.
To Reproduce:
Steps to reproduce the behaviour:
Copy the example code below
Run it and see the red outlining and the inability to submit the form
Swap the lines integerBind.Set(1)with w.SetContent(f)
Run it again and see that it works now
Screenshots:
With the SetContent line before the Set line:
With the SetContent line after the Set line:
Example code:
package main
import (
"fmt""strconv""fyne.io/fyne/v2/app""fyne.io/fyne/v2/data/binding""fyne.io/fyne/v2/widget"
)
funcmain() {
a:=app.New()
w:=a.NewWindow("Test")
varintegerintintegerBind:=binding.BindInt(&integer)
dayEntry:=widget.NewEntryWithData(binding.IntToString(integerBind))
dayEntry.Validator=func(sstring) error {
i, err:=strconv.Atoi(s)
iferr!=nil {
returnfmt.Errorf("Must be an integer")
}
ifi<1 {
returnfmt.Errorf("Must be bigger than zero")
}
returnnil
}
f:=widget.NewForm(
widget.NewFormItem("Integer", dayEntry),
)
f.SubmitText="Submit"f.OnSubmit=func() {
}
w.SetContent(f)
integerBind.Set(1) //works if this line is placed before the call to SetContentw.ShowAndRun()
}
Device (please complete the following information):
OS: MacOS
Version: Monterey 12.0.1
Go version: go1.17.1 darwin/arm64
Fyne version: 2.1.1
The text was updated successfully, but these errors were encountered:
I think we're running into the same thing, @Cookie04DE.
The screenshots show that the value in the Entryis updated, but the validator seems to not like it because the submit button is disabled. Changing the string in the form item in any way re-runs the validator and the submit button is enabled.
@andydotxyz or @Jacalz have you all had a chance to look at this? This code exhibits the same behavior.
Interesting! It seems that if the value is already valid, then the entry is still shown as valid even if it's set to a value that would not be accepted by the validator. In my code above I initialized someString to "a" and used _ = boundString.Set("123") instead.
So the root of this seems to be that the validator is not necessarily called when a binding is Set.
Describe the bug:
If you create a form and put in an entry with data, set a custom validator and change the data after you set the content of the window the entry will display an error even though the content is correct according to the validator and you won't be to submit the form.
To Reproduce:
Steps to reproduce the behaviour:
integerBind.Set(1)
withw.SetContent(f)
Screenshots:
With the SetContent line before the Set line:


With the SetContent line after the Set line:
Example code:
Device (please complete the following information):
The text was updated successfully, but these errors were encountered: