form-handling.go 1.2 KB

123456789101112131415161718192021222324252627282930
  1. package basics
  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. )
  9. var FormHandling = Doc(
  10. Markdown(`
  11. Form handling is an important part of web development. to make handling form easy,
  12. we have a global form that always be submitted with any event func. What you need to do
  13. is just to give an input a name.
  14. For example:
  15. `),
  16. ch.Code(generated.FormHandlingSample).Language("go"),
  17. utils.Demo("Form Handling", e00_basics.FormHandlingPagePath, "e00_basics/form-handling.go"),
  18. Markdown(`
  19. Use ~.Attr(web.VFieldName("Abc")...)~ to set the field name, make the name matches your data struct field name.
  20. So that you can ~ctx.UnmarshalForm(&fv)~ to set the values to data object. value of input must be set manually to set the initial value of form field.
  21. The fields which are bind with ~.Attr(web.VFieldName("Abc")...)~ are always submitted with every event func. A browser refresh, new page load will clear the form value.
  22. ~web.Scope(...).VSlot("{ plaidForm }")~ to nest a new form inside outside form, EventFunc inside will only post form values inside the scope.
  23. `),
  24. ).Title("Form Handling").
  25. Slug("basics/form-handling")