constructors.go 543 B

12345678910111213141516171819202122232425
  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: Name,
  13. Value: strFromPtr(Value),
  14. Class: "form-control",
  15. Type: "text",
  16. }
  17. }
  18. /* Generate new CharField field with type password */
  19. func NewPasswordField(Name string) *FormField {
  20. field := NewCharField(Name, nil).SetType("password")
  21. return field
  22. }