Exemplo n.º 1
0
func TestInlineCreation(t *testing.T) {
	form := NewForm("", POST, "/action.html").Elements(
		fields.TextField("text_field").SetLabel("Username"),
		FieldSet("psw_fieldset",
			fields.PasswordField("psw1").AddClass("password_class").SetLabel("Password 1"),
			fields.PasswordField("psw2").AddClass("password_class").SetLabel("Password 2"),
		),
		fields.SubmitButton("btn1", "Submit"),
	)
	t.Log("Rendered form:", form.Render())
}
Exemplo n.º 2
0
// NewFormFromModel returns a base form inferring fields, data types and contents from the provided instance.
// A Submit button is automatically added as a last field; the form is editable and fields can be added, modified or removed as needed.
// Tags can be used to drive automatic creation: change default widgets for each field, skip fields or provide additional parameters.
// Basic field -> widget mapping is as follows: string -> textField, bool -> checkbox, time.Time -> datetimeField, int -> numberField;
// nested structs are also converted and added to the form.
func NewFormFromModel(m interface{}, style string, args ...string) *Form {
	form := NewForm(style, args...)
	form.SetModel(m)
	flist, fsort := unWindStructure(m, "")
	for _, v := range flist {
		form.Elements(v.(FormElement))
	}
	form.Elements(FieldSet(
		"_button_group",
		fields.SubmitButton("submit", formcommon.LabelFn("Submit")),
		fields.ResetButton("reset", formcommon.LabelFn("Reset")),
	).SetTmpl("fieldset_buttons"))
	if fsort != "" {
		form.Sort(fsort)
	}
	return form
}
Exemplo n.º 3
0
func TestButtonRender(t *testing.T) {
	field := fields.SubmitButton("btn", "Click me!")
	field.SetStyle(style)
	t.Log("Rendered button:", field.Render())
	btn = field
}