Beispiel #1
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))
			}
		}
	}
}
Beispiel #2
0
func (ø *TableForm) SetSaveAction(row *pgsql.Row, id string) {
	ø.Action = func(f *FormHandler) (err error) {
		err = row.Fill(f.Map())
		if err != nil {
			return err
		}
		if id != "new" && len(row.Table.PrimaryKey) == 1 {
			row.Set(row.Table.PrimaryKey[0], id)
		}

		err = row.Save()
		return
	}
}