select-many.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package vuetifyx
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/qor5/web"
  6. h "github.com/theplant/htmlgo"
  7. )
  8. type VXSelectManyBuilder struct {
  9. tag *h.HTMLTagBuilder
  10. selectedItems interface{}
  11. items interface{}
  12. searchItemsFunc string
  13. }
  14. func VXSelectMany(children ...h.HTMLComponent) (r *VXSelectManyBuilder) {
  15. r = &VXSelectManyBuilder{
  16. tag: h.Tag("vx-selectmany").Children(children...),
  17. }
  18. return
  19. }
  20. func (b *VXSelectManyBuilder) Items(v interface{}) (r *VXSelectManyBuilder) {
  21. b.items = v
  22. return b
  23. }
  24. func (b *VXSelectManyBuilder) SelectedItems(v interface{}) (r *VXSelectManyBuilder) {
  25. b.selectedItems = v
  26. return b
  27. }
  28. func (b *VXSelectManyBuilder) SearchItemsFunc(v string) (r *VXSelectManyBuilder) {
  29. b.searchItemsFunc = v
  30. return b
  31. }
  32. func (b *VXSelectManyBuilder) ItemText(v string) (r *VXSelectManyBuilder) {
  33. b.tag.Attr("item-text", v)
  34. return b
  35. }
  36. func (b *VXSelectManyBuilder) ItemValue(v string) (r *VXSelectManyBuilder) {
  37. b.tag.Attr("item-value", v)
  38. return b
  39. }
  40. func (b *VXSelectManyBuilder) Label(v string) (r *VXSelectManyBuilder) {
  41. b.tag.Attr("label", v)
  42. return b
  43. }
  44. func (b *VXSelectManyBuilder) AddItemLabel(v string) (r *VXSelectManyBuilder) {
  45. b.tag.Attr("add-item-label", v)
  46. return b
  47. }
  48. func (b *VXSelectManyBuilder) FieldName(v string) (r *VXSelectManyBuilder) {
  49. b.tag.Attr(web.VFieldName(v)...)
  50. return b
  51. }
  52. func (b *VXSelectManyBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  53. if b.searchItemsFunc != "" {
  54. b.tag.Attr(":search-items-func", fmt.Sprintf(`function(val){return $plaid().eventFunc("%s").query("keyword", val).go()}`, b.searchItemsFunc))
  55. } else {
  56. b.tag.Attr(":items", b.items)
  57. }
  58. b.tag.Attr(":selected-items", b.selectedItems)
  59. return b.tag.MarshalHTML(ctx)
  60. }