constructors.go 566 B

1234567891011121314151617181920212223242526272829303132
  1. package form
  2. /* strFromPtr converts string pointer to a string */
  3. func strFromPtr(str *string) (s string) {
  4. if str != nil {
  5. s = *str
  6. }
  7. return
  8. }
  9. /* Generate new CharField field with type text */
  10. func NewCharField(Name string, Value *string) *FormField {
  11. return &FormField{
  12. Name,
  13. nil,
  14. "",
  15. strFromPtr(Value),
  16. "form-control",
  17. "text",
  18. "",
  19. "",
  20. false,
  21. false,
  22. nil,
  23. }
  24. }
  25. /* Generate new CharField field with type password */
  26. func NewPasswordField(Name string) *FormField {
  27. field := NewCharField(Name, nil).SetType("password")
  28. return &field
  29. }