event-handling.go 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package advanced_functions
  2. import (
  3. "github.com/qor5/docs/docsrc/examples/e00_basics"
  4. "github.com/qor5/docs/docsrc/generated"
  5. "github.com/qor5/docs/docsrc/utils"
  6. . "github.com/theplant/docgo"
  7. "github.com/theplant/docgo/ch"
  8. . "github.com/theplant/htmlgo"
  9. )
  10. var EventHandling = Doc(
  11. Markdown(`
  12. We extend vue to support the following types of event handling, so you can simply use go code to implement some complex logic.
  13. Using the ~~~Plaid()~~~ method will create an event handler that defaults to using the current ~~~vars~~~ and ~~~plaidForm~~~.
  14. The default http request method is ~~~Post~~~, if you want to use the ~~~Get~~~ method, you can also use the ~~~Get()~~~ method directly to create an event handler
  15. `),
  16. utils.Anchor(H2(""), "URL"),
  17. Markdown(`Request a page.`),
  18. ch.Code(generated.EventHandlingURLSample).Language("go"),
  19. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=url", "e00_basics/event-handling.go#L14-L22"),
  20. utils.Anchor(H2(""), "PushState"),
  21. Markdown(`Reqest a page and also changing the window location.`),
  22. ch.Code(generated.EventHandlingPushStateSample).Language("go"),
  23. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=pushstate", "e00_basics/event-handling.go#27-L35"),
  24. utils.Anchor(H2(""), "Reload"),
  25. Markdown(`Refresh page.`),
  26. ch.Code(generated.EventHandlingReloadSample).Language("go"),
  27. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=reload", "e00_basics/event-handling.go#40-L49"),
  28. utils.Anchor(H2(""), "Query"),
  29. Markdown(`Request a page with a query.`),
  30. ch.Code(generated.EventHandlingQuerySample).Language("go"),
  31. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=query", "e00_basics/event-handling.go#L54-L62"),
  32. utils.Anchor(H2(""), "MergeQuery"),
  33. Markdown(`Request a page with merging a query.`),
  34. ch.Code(generated.EventHandlingMergeQuerySample).Language("go"),
  35. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=merge_query", "e00_basics/event-handling.go#L67-L75"),
  36. utils.Anchor(H2(""), "ClearMergeQuery"),
  37. Markdown(`Request a page with clearing a query.`),
  38. ch.Code(generated.EventHandlingClearMergeQuerySample).Language("go"),
  39. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=clear_merge_query", "e00_basics/event-handling.go#L80-L88"),
  40. utils.Anchor(H2(""), "StringQuery"),
  41. Markdown(`Request a page with a query string.`),
  42. ch.Code(generated.EventHandlingStringQuerySample).Language("go"),
  43. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=string_query", "e00_basics/event-handling.go#L93-L101"),
  44. utils.Anchor(H2(""), "Queries"),
  45. Markdown(`Request a page with url.Values.`),
  46. ch.Code(generated.EventHandlingQueriesSample).Language("go"),
  47. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=queries", "e00_basics/event-handling.go#L106-L114"),
  48. utils.Anchor(H2(""), "PushStateURL"),
  49. Markdown(`Request a page with a url and also changing the window location.`),
  50. ch.Code(generated.EventHandlingQueriesSample).Language("go"),
  51. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=pushstateurl", "e00_basics/event-handling.go#L119-L127"),
  52. utils.Anchor(H2(""), "Location"),
  53. Markdown(`Open a page with more options.`),
  54. ch.Code(generated.EventHandlingLocationSample).Language("go"),
  55. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=location", "e00_basics/event-handling.go#L132-L140"),
  56. utils.Anchor(H2(""), "FieldValue"),
  57. Markdown(`Fill in a value on form.`),
  58. ch.Code(generated.EventHandlingFieldValueSample).Language("go"),
  59. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=fieldvalue", "e00_basics/event-handling.go#L145-L153"),
  60. utils.Anchor(H2(""), "FormClear"),
  61. Markdown(`Clear all form data.`),
  62. ch.Code(generated.EventHandlingFieldValueSample).Language("go"),
  63. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=formclear", "e00_basics/event-handling.go#L165-L178"),
  64. utils.Anchor(H2(""), "EventFunc"),
  65. Markdown(`Register an event func and call it when the event is triggered.`),
  66. ch.Code(generated.EventHandlingEventFuncSample).Language("go"),
  67. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=eventfunc", "e00_basics/event-handling.go#L183-L191"),
  68. utils.Anchor(H2(""), "Script"),
  69. Markdown(`Run a script code.`),
  70. ch.Code(generated.EventHandlingBeforeScriptSample).Language("go"),
  71. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=script", "e00_basics/event-handling.go#L196-L204"),
  72. utils.Anchor(H2(""), "Raw"),
  73. Markdown(`Directly call the js method`),
  74. ch.Code(generated.EventHandlingRawSample).Language("go"),
  75. utils.Demo("Event Handling", e00_basics.EventHandlingPagePath+"?api=raw", "e00_basics/event-handling.go#L209-L217"),
  76. ).Title("Event Handling").Slug("basics/event-handling")