shithub: mycel

Download patch

ref: 286d2f7e3fe365426c559b5ff8b48573ad1ce5ba
parent: 8c68719b7a3b8c7e4a1db663e6d2802a220924c5
author: Philip Silva <[email protected]>
date: Fri Dec 18 08:19:34 EST 2020

more generic version of ParentForm()

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -285,7 +285,7 @@
 		Text: t,
 		Font: n.Font(),
 		Click: func() (r duit.Event) {
-			b.submit(n.ParentForm().DomSubtree)
+			b.submit(n.Ancestor("form").DomSubtree)
 			return duit.Event{
 				Consumed:   true,
 				NeedLayout: true,
@@ -315,7 +315,7 @@
 				},
 				Keys: func(k rune, m draw.Mouse) (e duit.Event) {
 					if k == 10 {
-						browser.submit(n.ParentForm().DomSubtree)
+						browser.submit(n.Ancestor("form").DomSubtree)
 						return duit.Event{
 							Consumed:   true,
 							NeedLayout: true,
--- a/nodes/nodes.go
+++ b/nodes/nodes.go
@@ -75,15 +75,16 @@
 	return n.DomSubtree.Data
 }
 
-func (n *Node) ParentForm() *Node {
+// Ancestor of tag
+func (n *Node) Ancestor(tag string) *Node {
 	log.Printf("<%v>.ParentForm()", n.DomSubtree.Data)
-	if n.DomSubtree.Data == "form" {
-		log.Printf("  I'm a form :-)")
+	if n.DomSubtree.Data == tag {
+		log.Printf("  I'm a %v :-)", tag)
 		return n
 	}
 	if n.Parent != nil {
 		log.Printf("  go to my parent")
-		return n.Parent.ParentForm()
+		return n.Parent.Ancestor(tag)
 	}
 	return nil
 }