a08ad2786480dc1a92f22e12c2fc5fcd189c1788 — Sam Whited 4 months ago e0d1146 fields
form: provide access to fixed fields with no var

The data forms spec says that fixed fields do not have to have a
variable name since they can't be set anyways.
However, we currently rely on the variable name to get the value of
fields when iterating over all fields in a form.
This patch adds the raw, wire-format, untyped value of each field to its
data when iterating so that it can be used for fixed fields that cannot
be referenced otherwise, and for debugging.

Signed-off-by: Sam Whited <sam@samwhited.com>
2 files changed, 9 insertions(+), 0 deletions(-)

M form/fields.go
M form/form.go
M form/fields.go => form/fields.go +8 -0
@@ 69,6 69,14 @@ type FieldData struct {
	Label    string
	Desc     string
	Required bool

	// Raw is the value of the field as it came over the wire with no type
	// information.
	// Generally speaking, Get methods on form should be used along with the field
	// data's Var value to fetch fields and Raw should be ignored.
	// Raw is mostly provided to access fixed type fields that do not have a
	// variable name (and therefore cannot be referenced or set).
	Raw []string

type field struct {

M form/form.go => form/form.go +1 -0
@@ 79,6 79,7 @@ func (d *Data) ForFields(f func(FieldData)) {
			Label:    field.label,
			Desc:     field.desc,
			Required: field.required,
			Raw:      field.value,