123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package e23_vuetify_components_kitchen
- // @snippet_begin(VuetifyComponentsKitchen)
- import (
- "github.com/qor5/docs/docsrc/utils"
- . "github.com/qor5/ui/vuetify"
- "github.com/qor5/web"
- h "github.com/theplant/htmlgo"
- )
- var globalCities = []string{"Tokyo", "Hangzhou", "Shanghai"}
- type formVals struct {
- Cities1 []string
- Cities2 []string
- MyItem string
- }
- var fv = formVals{
- Cities1: []string{
- "TK",
- "LD",
- },
- Cities2: []string{
- "Hangzhou",
- "Shanghai",
- },
- MyItem: "VItem2",
- }
- func VuetifyComponentsKitchen(ctx *web.EventContext) (pr web.PageResponse, err error) {
- var chips h.HTMLComponents
- for _, city := range globalCities {
- chips = append(chips,
- VChip(h.Text(city)).
- Close(true).
- Attr("@click:close", web.POST().EventFunc("removeCity").Query("city", city).Go()),
- )
- }
- pr.Body = VContainer(
- utils.PrettyFormAsJSON(ctx),
- h.H1("Chips delete"),
- chips,
- h.H1("Chips group"),
- VChipGroup(
- VChip(
- h.Text("Hangzhou"),
- VIcon("star").Right(true),
- ).Value("HZ"),
- VChip(h.Text("Shanghai")).Value("SH").Filter(true).Label(true),
- VChip(h.Text("Tokyo")).Value("TK").Filter(true),
- VChip(h.Text("New York")).Value("NY"),
- VChip(h.Text("London")).Value("LD"),
- ).ActiveClass("indigo darken-3 white--text").
- // Mandatory(true).
- FieldName("Cities1").
- Value(fv.Cities1).
- Multiple(true),
- VAutocomplete().
- Items(globalCities).
- FieldName("Cities2").
- Value(fv.Cities2),
- h.H1("Items Group"),
- VItemGroup(
- VContainer(
- VRow(
- VCol(
- VItem(
- VCard(
- VCardTitle(h.Text("Item1")),
- ).Attr(":color", "active ? \"primary\" : \"\"").
- Attr("@click", "toggle"),
- ).Value("VItem1").Attr("v-slot", "{active, toggle}"),
- ),
- VCol(
- VItem(
- VCard(
- VCardTitle(h.Text("Item2")),
- ).Attr(":color", "active ? \"primary\" : \"\"").
- Attr("@click", "toggle"),
- ).Value("VItem2").Attr("v-slot", "{active, toggle}"),
- ),
- ),
- ),
- ).FieldName("MyItem").
- Value(fv.MyItem),
- VBtn("Submit").
- OnClick("submit"),
- )
- return
- }
- func submit(ctx *web.EventContext) (r web.EventResponse, err error) {
- fv = formVals{}
- ctx.MustUnmarshalForm(&fv)
- r.Reload = true
- return
- }
- func removeCity(ctx *web.EventContext) (r web.EventResponse, err error) {
- city := ctx.R.FormValue("city")
- var newCities []string
- for _, c := range globalCities {
- if c != city {
- newCities = append(newCities, c)
- }
- }
- globalCities = newCities
- r.Reload = true
- return
- }
- var VuetifyComponentsKitchenPB = web.Page(VuetifyComponentsKitchen).
- EventFunc("removeCity", removeCity).
- EventFunc("submit", submit)
- const VuetifyComponentsKitchenPath = "/samples/vuetify-components-kitchen"
- // @snippet_end
|