~samwhited/xmpp

7503b0930385138dcc6f6f83b9de8a4886d12bd5 — Sam Whited 4 years ago 3b6153d
form: Fix broken options
2 files changed, 18 insertions(+), 25 deletions(-)

M form/fields.go
M form/options.go
M form/fields.go => form/fields.go +17 -24
@@ 10,13 10,13 @@ import (

// A field represents a data field that may be added to a form.
type field struct {
	XMLName  xml.Name   `xml:"jabber:x:data field"`
	XMLName  xml.Name   `xml:"field"`
	Typ      string     `xml:"type,attr"`
	Var      string     `xml:"var,attr,omitempty"`
	Label    string     `xml:"label,attr,omitempty"`
	Desc     string     `xml:"desc,omitempty"`
	Value    []string   `xml:"value,omitempty"`
	Required struct{}   `xml:"required,omitempty"`
	Required *struct{}  `xml:"required,omitempty"`
	Option   []fieldopt `xml:"option,omitempty"`
}



@@ 25,12 25,10 @@ type fieldopt struct {
	Value   string   `xml:"value,omitempty"`
}

// Boolean fields enable an entity to gather or provide an either-or choice
// between two options.
func Boolean(varName string, o ...FieldOption) Option {
func newField(typ, varName string, o ...FieldOption) func(data *Data) {
	return func(data *Data) {
		f := field{
			Typ: "boolean",
			Typ: typ,
			Var: varName,
		}
		getFieldOpts(&f, o...)


@@ 38,63 36,58 @@ func Boolean(varName string, o ...FieldOption) Option {
	}
}

func fieldOpt(typ, varName string, o ...FieldOption) func(data *Data) {
	return func(data *Data) {
		f := field{
			Typ: "typ",
			Var: varName,
		}
		getFieldOpts(&f, o...)
		data.children = append(data.children, f)
	}
// Boolean fields enable an entity to gather or provide an either-or choice
// between two options.
func Boolean(varName string, o ...FieldOption) Option {
	return newField("boolean", "", o...)
}

// Fixed is intended for data description (e.g., human-readable text such as
// "section" headers) rather than data gathering or provision.
func Fixed(o ...FieldOption) Option {
	return fieldOpt("fixed", "")
	return newField("fixed", "", o...)
}

// Hidden fields are not shown by the form-submitting entity, but instead are
// returned, generally unmodified, with the form.
func Hidden(varName string, o ...FieldOption) Option {
	return fieldOpt("hidden", varName)
	return newField("hidden", varName, o...)
}

// JIDMulti enables an entity to gather or provide multiple Jabber IDs.
func JIDMulti(varName string, o ...FieldOption) Option {
	return fieldOpt("jid-multi", varName)
	return newField("jid-multi", varName, o...)
}

// JID enables an entity to gather or provide a Jabber ID.
func JID(varName string, o ...FieldOption) Option {
	return fieldOpt("jid-single", varName)
	return newField("jid-single", varName, o...)
}

// ListMulti enables an entity to gather or provide one or more entries from a
// list.
func ListMulti(varName string, o ...FieldOption) Option {
	return fieldOpt("list-multi", varName)
	return newField("list-multi", varName, o...)
}

// ListSingle enables an entity to gather or provide a single entry from a list.
func ListSingle(varName string, o ...FieldOption) Option {
	return fieldOpt("list-single", varName)
	return newField("list-single", varName, o...)
}

// TextMulti enables an entity to gather or provide multiple lines of text.
func TextMulti(varName string, o ...FieldOption) Option {
	return fieldOpt("text-multi", varName)
	return newField("text-multi", varName, o...)
}

// TextPrivate enables an entity to gather or provide a line of text that should
// be obscured in the submitting entities interface (eg. with multiple
// asterisks).
func TextPrivate(varName string, o ...FieldOption) Option {
	return fieldOpt("text-private", varName)
	return newField("text-private", varName, o...)
}

// TextSingle enables an entity to gather or provide a line of text.
func TextSingle(varName string, o ...FieldOption) Option {
	return fieldOpt("text-single", varName)
	return newField("text-single", varName, o...)
}

M form/options.go => form/options.go +1 -1
@@ 40,7 40,7 @@ var (

var (
	required FieldOption = func(f *field) {
		f.Required = struct{}{}
		f.Required = &struct{}{}
	}
)