What is the correct usage of 'window.Confirm'? #13
Answered
by
Splizard
SteveMaybe
asked this question in
Q&A
-
Say in an app a developer wants a user to confirm before completing something, maybe a delete action on the server. I found the How does this look? func main() {
app.New("Hello World",
div.New(text.Set("Do Thing Maybe"),
client.OnClick(js.Script(func(ctx js.Ctx) {
ctx.If(window.Confirm(client.NewString("Are you sure?")), js.Script(func(ctx js.Ctx) {
ctx(client.Go(func() {
println("Some server call..")
}))
})).Else(window.Alert(client.NewString("Canceled Action")))
})),
),
).Launch()
} |
Beta Was this translation helpful? Give feedback.
Answered by
Splizard
Jan 17, 2021
Replies: 1 comment 1 reply
-
Yep, that works, however you are using the low-level JS scripting API. package main
import (
"qlova.org/seed/client"
"qlova.org/seed/new/app"
"qlova.org/seed/new/column"
"qlova.org/seed/new/text"
"qlova.org/seed/use/js/window"
)
func main() {
app.New("Hello World",
column.New(
text.Set("Do Thing Maybe"),
client.OnClick(
client.If(window.Confirm(client.NewString("Are you sure?")),
client.Go(func() {
println("Some server call..")
}),
).Else(
window.Alert(client.NewString("Canceled Action")),
),
),
),
).Launch()
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Splizard
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, that works, however you are using the low-level JS scripting API.
Using the client package's If function, you can achieve the same thing with more clarity.
https://pkg.go.dev/qlova.org/[email protected]/client#If