Common isomorphic functionality in one kit.

formjs.go 843B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // The Isomorphic Go Project
  2. // Copyright (c) Wirecog, LLC. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license, which can be found in the LICENSE file.
  5. // +build clientonly
  6. package isokit
  7. import (
  8. "honnef.co/go/js/dom"
  9. )
  10. type Form interface {
  11. Validate() bool
  12. AutofillFields() []string
  13. Fields() map[string]string
  14. Errors() map[string]string
  15. // SetError(key string, message string)
  16. }
  17. func FormValue(fp *FormParams, key string) string {
  18. var result string
  19. field := fp.FormElement.QuerySelector("[name=" + key + "]")
  20. switch field.(type) {
  21. case *dom.HTMLInputElement:
  22. result = field.(*dom.HTMLInputElement).Value
  23. case *dom.HTMLTextAreaElement:
  24. result = field.(*dom.HTMLTextAreaElement).Value
  25. case *dom.HTMLSelectElement:
  26. result = field.(*dom.HTMLSelectElement).Value
  27. }
  28. return result
  29. }