I just started learning Go coming from JS/TS. I want to validate an entry in fyne on loss of focus.
I got it to work like this :
type dateEntry struct {
widget.Entry
}
func NewDateEntry() *dateEntry {
entry := &dateEntry{}
entry.ExtendBaseWidget(entry)
return entry
}
func (e *dateEntry) FocusLost() {
println("Focus lost")
e.Validate()
}
func main() {
dateInput := NewDateEntry()
dateInput.SetPlaceHolder("DD/MM/YYYY")
dateInput.Validator = func(s string) (err error) {
reDate := regexp.MustCompile("(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)")
if s == "" {
return fmt.Errorf("date required")
} else if !reDate.MatchString(s) {
return fmt.Errorf("date invalid")
}
return nil
}
w.SetContent(dateInput)
w.ShowAndRun()
}
There seems to be a lot of code just to trigger a function on loss of focus. Is there a simpler way to do this?
Now the blue line at the bottom of the input is no longer displayed anymore when focus is gained, how can I keep the style when focus is gained while handling a focus loss event?