Skip to content

Commit

Permalink
Merge branch 'release/v1.4.x' into fix/1533
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Nov 16, 2020
2 parents 97a53be + 96c38fb commit 0e65e1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ More detailed release notes can be found on the [releases page](https://github.c
### Changed

* Table columns can now be different sizes using SetColumnWidth
* Avoid unnecessary validation check on Refresh in widget.Form

### Fixed

Expand All @@ -24,6 +25,7 @@ More detailed release notes can be found on the [releases page](https://github.c
* iOS: Missing CFBundleIconName and asset catalog (#1504)
* CenterOnScreen causes crash on MacOS when called from goroutine (#1539)
* desktop.MouseHover Button state is not reliable (#1533)
* Initial validation status in widget.Form is not respected


## 1.4 - 1 November 2020
Expand Down
18 changes: 9 additions & 9 deletions widget/form.go
Expand Up @@ -111,23 +111,22 @@ func (f *Form) updateButtons() {
} else {
f.buttonBox.Show()
}

f.checkValidation()
}

func (f *Form) checkValidation() {
for i, item := range f.Items {
for _, item := range f.Items {
if item.validationError != nil {
f.submitButton.Disable()
break
} else if i == len(f.Items)-1 {
f.submitButton.Enable()
return
}
}

f.submitButton.Enable()
}

func (f *Form) setUpValidation(widget fyne.CanvasObject, i int) {
if w, ok := widget.(fyne.Validatable); ok {
f.Items[i].validationError = w.Validate()
w.SetOnValidationChanged(func(err error) {
f.Items[i].validationError = err
if err != nil {
Expand Down Expand Up @@ -155,8 +154,8 @@ func (f *Form) CreateRenderer() fyne.WidgetRenderer {
f.ExtendBaseWidget(f)
itemGrid := fyne.NewContainerWithLayout(layout.NewFormLayout(), []fyne.CanvasObject{}...)
for i, item := range f.Items {
itemGrid.AddObject(f.createLabel(item.Text))
itemGrid.AddObject(item.Widget)
itemGrid.Add(f.createLabel(item.Text))
itemGrid.Add(item.Widget)
f.setUpValidation(item.Widget, i)
}
f.itemGrid = itemGrid
Expand All @@ -167,7 +166,8 @@ func (f *Form) CreateRenderer() fyne.WidgetRenderer {
f.buttonBox = NewHBox(layout.NewSpacer(), f.cancelButton, f.submitButton)

renderer := cache.Renderer(NewVBox(f.itemGrid, f.buttonBox))
f.updateButtons() // will set correct visibility on the submit/cancel btns
f.updateButtons() // will set correct visibility on the submit/cancel btns
f.checkValidation() // make sure to check initial validation status
return renderer
}

Expand Down

0 comments on commit 0e65e1c

Please sign in to comment.