Skip to content
Gx
GitHub

GX4008: signal-bound fields need rules or gx.Unchecked

An action input reads a signal and has no rules.

Cause

An action input reads a signal and has no rules. The browser controls each signal value, so the server must check it.

Example

cart/Button.gx
package cart

import "app/cart/route"

signals {
  Qty int = 1
}

<button on:click={route.Add{}}>Add</button>
cart/cart.go
package cart

import (
	"github.com/alternayte/gx"
	"app/cart/route"
)

var Add = gx.Action(func(c *gx.Ctx, in route.Add) error { return nil })
cart/route/route.go
package route

import "github.com/alternayte/gx"

type Add struct {
	gx.Route `POST /cart/add`
	Qty      int `signal:"qty"`
}

gx check reports:

gx check
cart/route/route.go:5:6: GX4008: action "Add" has signal-bound fields; add Rules() or embed gx.Unchecked

Fix

  1. Add a Rules method with a rule for each signal field.
  2. Or embed gx.Unchecked in the input type when the value needs no check.