예제 #1
0
// sets all true and false values to the given text
func (ø *TableForm) SetBoolTexts(trueText string, falseText string) {
	for n, f := range ø.Fields {
		if f.Type == Bool {
			elem := ø.FieldElement(n)
			trueOpt := elem.Any(h.And_(h.Attr("value", "true"), h.Tag("option")))
			if trueOpt != nil {
				trueOpt.SetContent(trueText)
			}
			falseOpt := elem.Any(h.And_(h.Attr("value", "false"), h.Tag("option")))
			if falseOpt != nil {
				falseOpt.SetContent(falseText)
			}
		}
	}
}
예제 #2
0
func (ø *TableForm) SetValues(row *pgsql.Row) {
	props := row.AsStrings()
	for k, v := range props {
		if !ø.HasFieldDefinition(k) {
			continue
		}
		elem := ø.FieldElement(k)
		if elem.Tag() == "select" {
			option := elem.Any(h.And_(h.Attr("value", v), h.Tag("option")))
			if option != nil {
				option.Add(h.Attr("selected", "selected"))
			}
		} else {
			if elem.Tag() == "textarea" {
				elem.Add(v)
			} else {
				//tp := elem.Attribute("type")
				//if tp == "date" {
				if elem.HasClass("date") {
					var tme time.Time
					field := row.Table.Field(k)
					row.Get(field, &tme)
					year, month, day := tme.Date()
					// %02.0f.%02.0f.%4.0f
					v = fmt.Sprintf("%4.0f-%02.0f-%02.0f", float64(year), float64(int(month)), float64(day))
				}
				elem.Add(h.Attr("value", v))
			}
		}
	}
}
예제 #3
0
func (ø *TableForm) Select(fld string) (e *h.Element) {
	e = ø.Any(h.And_(h.Tag("select"), h.Id(fld)))
	return
}
예제 #4
0
func (ø *TableForm) Label(fld string) (e *h.Element) {
	e = ø.Any(h.And_(h.Tag("label"), h.Attr("for", fld)))
	return
}