Example #1
0
func or(args ...interface{}) interface{} {
	for _, v := range args {
		t, _ := types.IsTrue(v)
		if t {
			return v
		}
	}
	return args[len(args)-1]
}
Example #2
0
func (f *Form) writeInput(buf *bytes.Buffer, itype string, field *Field) error {
	if err := f.beginInput(buf, field, -1); err != nil {
		return err
	}
	attrs := html.Attrs{
		"id":   field.Id(),
		"type": itype,
		"name": field.HTMLName,
	}
	if err := f.prepareFieldAttributes(field, attrs, -1); err != nil {
		return err
	}
	switch field.Type {
	case CHECKBOX:
		if t, ok := types.IsTrue(field.value.Interface()); t && ok {
			attrs["checked"] = "checked"
		}
	case TEXT, PASSWORD, EMAIL, HIDDEN:
		attrs["value"] = html.Escape(types.ToString(field.Value()))
		if field.Placeholder != "" {
			attrs["placeholder"] = html.Escape(field.Placeholder.TranslatedString(f.ctx))
		}
		if ml, ok := field.Tag().MaxLength(); ok {
			attrs["maxlength"] = strconv.Itoa(ml)
		}
	case FILE:
	default:
		panic("unreachable")
	}
	f.openTag(buf, "input", attrs)
	if field.Type == CHECKBOX {
		// Close the label before calling EndInput
		if err := f.endLabel(buf, field, field.Label.TranslatedString(f.ctx), -1); err != nil {
			return err
		}
	}
	if err := f.endInput(buf, field, -1); err != nil {
		return err
	}
	return nil
}
Example #3
0
func not(arg interface{}) bool {
	t, _ := types.IsTrue(arg)
	return !t
}