partial-update.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package e00_basics
  2. // @snippet_begin(PartialUpdateSample)
  3. import (
  4. "time"
  5. "github.com/qor5/web"
  6. . "github.com/theplant/htmlgo"
  7. )
  8. func PartialUpdatePage(ctx *web.EventContext) (pr web.PageResponse, err error) {
  9. pr.Body = Div(
  10. H1("Partial Update"),
  11. A().Text("Edit").Href("javascript:;").
  12. Attr("@click", web.POST().EventFunc("edit1").Go()),
  13. web.Portal(
  14. Text("original portal content here"),
  15. ).Name("part1"),
  16. Div().Text(time.Now().Format(time.RFC3339Nano)),
  17. )
  18. return
  19. }
  20. func edit1(ctx *web.EventContext) (er web.EventResponse, err error) {
  21. er.UpdatePortals = append(er.UpdatePortals, &web.PortalUpdate{
  22. Name: "part1",
  23. Body: Div(
  24. Fieldset(
  25. Legend("Input value"),
  26. Div(
  27. Label("Title"),
  28. Input("").Type("text"),
  29. ),
  30. Div(
  31. Label("Date"),
  32. Input("").Type("date"),
  33. ),
  34. ),
  35. Button("Update").
  36. Attr("@click", web.POST().EventFunc("reload2").Go()),
  37. ),
  38. })
  39. return
  40. }
  41. func reload2(ctx *web.EventContext) (er web.EventResponse, err error) {
  42. er.Reload = true
  43. return
  44. }
  45. var PartialUpdatePagePB = web.Page(PartialUpdatePage).
  46. EventFunc("edit1", edit1).
  47. EventFunc("reload2", reload2)
  48. const PartialUpdatePagePath = "/samples/partial_update"
  49. // @snippet_end