Hi there, Hope you are having a great day/night.
Sorry in advance for the links but as a new user I can can only use 2 mdlinks.
I’m trying to parse a form on submit in order to get its keys/values. I’am using FormData interface https://developer.mozilla.org/en-US/docs/Web/API/FormData to do it with the package HTML - from GoWebApi https://pkg.go.dev/github.com/gowebapi/webapi@v0.0.0-20220111190827-0cb1f8ede1ac/html
However, I am not able to loop through it, as I am confused about how to make callback from ForEach https://pkg.go.dev/github.com/gowebapi/webapi@v0.0.0-20220111190827-0cb1f8ede1ac/html?utm_source=gopls#FormData.ForEach
func (*FormData) ForEach ¶
func (_this *FormData) ForEach(callback *FormDataForEach, optionalThisForCallbackArgument interface{})
Here my Code:
func (p *Page) onInc(e *vecty.Event) {
formEl := html.HTMLFormElementFromJS(DocumentGetElementById"form333").JSValue())
formData := html.NewFormData(formEl)
dataLoop := formData.ForEach()
---< callback here >----
for k, v := range dataLoop {
println(k,v)
}
}
Here the form elements:
<form id="form333" style="margin: 0px;"><label for="Fname">First name:</label><br><input type="text" id="Fname" name="Fname"><br><label for="Lname">Last name:</label><br><input id="Lname" type="text" name="Lname"><input type="submit" value="Text input" class="button is-danger"></form>
According the doc I need to make a FormDataForEach Callback & optionalThisForCallbackArgument interface{} but I have no clue how to that after I tried to that the last 24 hours and as im new in GO.
I also tried other functions such as:
-
FormDataForEachFromJS -
https://pkg.go.dev/github.com/gowebapi/webapi@v0.0.0-20220111190827-0cb1f8ede1ac/html?utm_source=gopls#FormDataForEachFromJS
-
FormDataEntryIteratorValueFromJS
https://pkg.go.dev/github.com/gowebapi/webapi@v0.0.0-20220111190827-0cb1f8ede1ac/html?utm_source=gopls#FormDataEntryIteratorValueFromJS
-
ArrayFromJS
https://pkg.go.dev/github.com/gowebapi/webapi@v0.0.0-20220111190827-0cb1f8ede1ac/javascript#ArrayFromJS
from
https://pkg.go.dev/github.com/gowebapi/webapi@v0.0.0-20220111190827-0cb1f8ede1ac/javascript
I have not been able to make it working so far, and i’am totally confused.
so, if somebody can show me how to handle the callback or any other ways to get the formdata key,value would be greatly appreciated.
Thanks in advance.
nb:
-
I am not using
syscall/js
which is not working even though I set"go.toolsEnvVars": { "GOARCH":"wasm", "GOOS":"js", }, "go.testEnvVars": {"GOARCH":"wasm", "GOOS":"js", }
in vscode settings.json -
I am not using other useful libraries like
https://github.com/gorilla/schema
because I only use the dom and not http.request.