shithub: mycel

Download patch

ref: a5214c3c2a9396417edd4658e1344126da856ba9
parent: 0f6260b296b7a1542e278cab6ed41314df8eebbe
author: Philip Silva <[email protected]>
date: Sun Jan 10 13:57:25 EST 2021

Fix submit closure

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -319,6 +319,9 @@
 		t = "Submit"
 	}
 
+	// TODO: would be better to deal with *nodes.Node but keeping the correct
+	// references in the closure is tricky. Probably better to write a separate
+	// type Button to avoid this problem completely.
 	click := func() (r duit.Event) {
 		f := n.Ancestor("form")
 
@@ -326,7 +329,7 @@
 			return
 		}
 
-		b.submit(f, n)
+		b.submit(f.DomSubtree, n.DomSubtree)
 
 		return duit.Event{
 			Consumed:   true,
@@ -359,7 +362,7 @@
 				},
 				Keys: func(k rune, m draw.Mouse) (e duit.Event) {
 					if k == 10 {
-						browser.submit(n.Ancestor("form"), nil)
+						browser.submit(n.Ancestor("form").DomSubtree, nil)
 						return duit.Event{
 							Consumed:   true,
 							NeedLayout: true,
@@ -387,7 +390,6 @@
 			}
 		}
 	}
-
 	x := m.Point.X
 	y := m.Point.Y
 	maxX := self.R.Dx()
@@ -396,7 +398,6 @@
 		dui.Display.SetCursor(&draw.Cursor{
 			Set: cursor,
 		})
-
 		if m.Buttons == 0 {
 			r.Consumed = true
 			return r
@@ -535,7 +536,6 @@
 		} else if len(rows[0]) == 1 {
 			return rows[0][0]
 		}
-
 		return NewElement(horizontalSeq(true, rows[0]), n)
 	} else {
 		seqs := make([]*Element, 0, len(rows))
@@ -543,7 +543,6 @@
 			seq := horizontalSeq(true, row)
 			seqs = append(seqs, NewElement(seq, n))
 		}
-
 		return NewElement(verticalSeq(seqs), n)
 	}
 }
@@ -748,7 +747,6 @@
 				seqs = append(seqs, NewElement(seq, row.n))
 			}
 		}
-
 		return NewElement(verticalSeq(seqs), n)
 	}
 }
--- a/browser/website.go
+++ b/browser/website.go
@@ -169,17 +169,17 @@
 	log.Flush()
 }
 
-func formData(n, submitBtn *nodes.Node) (data url.Values) {
+func formData(n, submitBtn *html.Node) (data url.Values) {
 	data = make(url.Values)
-	if n.Data() == "input" {
-		if n.Attr("type") == "submit" && (submitBtn == nil || n.DomSubtree != submitBtn.DomSubtree) {
+	if n.Data == "input" {
+		if attr(*n, "type") == "submit" && n != submitBtn {
 			return
 		}
-		if k := n.Attr("name"); k != "" {
-			data.Set(k, n.Attr("value"))
+		if k := attr(*n, "name"); k != "" {
+			data.Set(k, attr(*n, "value"))
 		}
 	}
-	for _, c := range n.Children {
+	for c := n.FirstChild; c != nil; c = c.NextSibling {
 		for k, vs := range formData(c, submitBtn) {
 			data.Set(k, vs[0]) // TODO: what aboot the rest?
 		}
@@ -187,18 +187,17 @@
 	return
 }
 
-func (b *Browser) submit(form, submitBtn *nodes.Node) {
+func (b *Browser) submit(form *html.Node, submitBtn *html.Node) {
 	var err error
 	var buf []byte
 	var contentType opossum.ContentType
 
 	method := "GET" // TODO
-	if m := form.Attr("method"); m != "" {
+	if m := attr(*form, "method"); m != "" {
 		method = strings.ToUpper(m)
 	}
-
 	uri := b.URL()
-	if action := form.Attr("action"); action != "" {
+	if action := attr(*form, "action"); action != "" {
 		uri, err = b.LinkedUrl(action)
 		if err != nil {
 			log.Printf("error parsing %v", action)
@@ -205,7 +204,6 @@
 			return
 		}
 	}
-
 
 	if method == "GET" {
 		q := uri.Query()