select-fix.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package vuetifyx
  2. import (
  3. "context"
  4. "github.com/qor5/ui/vuetify"
  5. h "github.com/theplant/htmlgo"
  6. )
  7. type VXSelectBuilder struct {
  8. tag *h.HTMLTagBuilder
  9. selectedItems interface{}
  10. items interface{}
  11. }
  12. func VXSelect(children ...h.HTMLComponent) (r *VXSelectBuilder) {
  13. r = &VXSelectBuilder{
  14. tag: h.Tag("vx-select").Children(children...),
  15. }
  16. return
  17. }
  18. func (b *VXSelectBuilder) ErrorMessages(v ...string) (r *VXSelectBuilder) {
  19. vuetify.SetErrorMessages(b.tag, v)
  20. return b
  21. }
  22. func (b *VXSelectBuilder) Items(v interface{}) (r *VXSelectBuilder) {
  23. b.items = v
  24. return b
  25. }
  26. func (b *VXSelectBuilder) SelectedItems(v interface{}) (r *VXSelectBuilder) {
  27. b.selectedItems = v
  28. return b
  29. }
  30. func (b *VXSelectBuilder) FieldName(v string) (r *VXSelectBuilder) {
  31. b.tag.Attr("field-name", v)
  32. return b
  33. }
  34. func (b *VXSelectBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  35. if b.items == nil {
  36. b.items = b.selectedItems
  37. }
  38. b.tag.Attr(":items", b.items)
  39. b.tag.Attr(":selected-items", b.selectedItems)
  40. return b.tag.MarshalHTML(ctx)
  41. }