diff --git a/validation.go b/validation.go index 495aaf1b8c..01f95097bb 100644 --- a/validation.go +++ b/validation.go @@ -16,6 +16,11 @@ type ExpandedValidator interface { // SetValidationError manually updates the validation status until the next input change. SetValidationError(error) + + // ShouldDisplayValidation tells a parent widget if the validatable widget wants to currently display + // the validation error. This can be used to avoid "nagging" the user about errors until it makes + // sense to show it. I.e. an empty widget.Entry that hasn't been interacted with does not show the error. + ShouldDisplayValidation() bool } // Validatable is an interface for specifying if a widget is validatable. diff --git a/widget/entry_validation.go b/widget/entry_validation.go index 79f7f2b99f..0b1d088e45 100644 --- a/widget/entry_validation.go +++ b/widget/entry_validation.go @@ -63,6 +63,14 @@ func (e *Entry) SetValidationError(err error) { } } +// ShouldDisplayValidation returns true if the entry has not been interacted with +// or is currently focused. +// +// Since: 2.5 +func (e *Entry) ShouldDisplayValidation() bool { + return !e.dirty || e.focused +} + var _ fyne.Widget = (*validationStatus)(nil) type validationStatus struct { diff --git a/widget/form.go b/widget/form.go index 8f5ba5028d..22a00b3f93 100644 --- a/widget/form.go +++ b/widget/form.go @@ -296,10 +296,10 @@ func (f *Form) updateHelperText(item *FormItem) { if item.helperOutput == nil { return // testing probably, either way not rendered yet } - showHintIfError := false - if e, ok := item.Widget.(*Entry); ok && (!e.dirty || e.focused) { - showHintIfError = true - } + + ev, ok := item.Widget.(fyne.ExpandedValidator) + showHintIfError := ok && ev.ShouldDisplayValidation() + if item.validationError == nil || showHintIfError { item.helperOutput.Text = item.HintText item.helperOutput.Color = theme.PlaceHolderColor()