Skip to content

Commit

Permalink
Merge pull request fyne-io#1920 from zdima/zdima-patch-1
Browse files Browse the repository at this point in the history
The onConfirm callback should be called only when user click on 'Ok' of a EntryDialog dialog.
  • Loading branch information
Jacalz committed Feb 8, 2021
2 parents 0e09c18 + 4bd08e5 commit 6193bd8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dialog/entry.go
Expand Up @@ -49,9 +49,9 @@ func (i *EntryDialog) SetOnClosed(callback func()) {
func NewEntryDialog(title, message string, onConfirm func(string), parent fyne.Window) *EntryDialog {
i := &EntryDialog{entry: widget.NewEntry()}
items := []*widget.FormItem{widget.NewFormItem(message, i.entry)}
i.formDialog = NewForm(title, "Ok", "Cancel", items, func(_ bool) {
i.formDialog = NewForm(title, "Ok", "Cancel", items, func(ok bool) {
// User has confirmed and entered an input
if onConfirm != nil {
if ok && onConfirm != nil {
onConfirm(i.entry.Text)
}

Expand Down
32 changes: 32 additions & 0 deletions dialog/entry_test.go
@@ -0,0 +1,32 @@
package dialog

import (
"testing"

"fyne.io/fyne/v2/test"
"github.com/stretchr/testify/assert"
)

func TestEntryDialog_Confirm(t *testing.T) {
value := ""
ed := NewEntryDialog("Test", "message", func(v string) {
value = v
}, test.NewWindow(nil))
ed.Show()
test.Type(ed.entry, "123")
test.Tap(ed.confirm)

assert.Equal(t, value, "123", "Control form should be confirmed with no validation")
}

func TestEntryDialog_Dismiss(t *testing.T) {
value := "123"
ed := NewEntryDialog("Test", "message", func(v string) {
value = v
}, test.NewWindow(nil))
ed.Show()
test.Type(ed.entry, "XYZ")
test.Tap(ed.cancel)

assert.Equal(t, value, "123", "Control form should not change value on dismiss")
}

0 comments on commit 6193bd8

Please sign in to comment.