GX6006: widget input field cannot be an attribute
A field of the route input of a widget has a type that an attribute of an element cannot hold.
Cause
A field of the route input of a widget has a type that an attribute of an element cannot hold. The fields of the input are the attributes of the element. An attribute is text, so a field is a string, a number, a bool, or a named type of one of these.
Example
package cart
props {
Currency string
}
<section>
<p>Your cart in {p.Currency}</p>
</section>package route
import "github.com/alternayte/gx"
type Widget struct {
gx.Route `GET /widgets/cart`
Currency string `query:"currency" default:"EUR"`
Coupons []string `query:"coupons"`
}package cart
import (
"github.com/alternayte/gx"
"app/cart/route"
)
var CartWidget = gx.Widget(func(c *gx.Ctx, in route.Widget) (CartProps, error) {
return CartProps{Currency: in.Currency}, nil
}, Cart).Tag("acme-cart")
var Routes = gx.Collect(CartWidget)gx check reports:
cart/route/route.go:8:2: GX6006: field "Coupons" of the widget input "Widget" has the type []string; an attribute holds a string, a number or a boolFix
- Give the widget an id as an attribute, and load the list or the object in the loader of the widget.
- For a small set of values, use a string type with constants.