Example #1
0
func GetElement(in *pgsql.Field) (out *h.Element) {
	if in.Selection != nil {
		return SELECT()
	}
	if pgsql.IsVarChar(in.Type) {
		return INPUT(h.Attr("type", "text"))
	}

	if in.Type == pgsql.BoolType {
		return SELECT(
			OPTION(h.Attr("value", "true"), "true"),
			OPTION(h.Attr("value", "false"), "false"),
		)
	}

	switch in.Type {
	case pgsql.TextType:
		return TEXTAREA()
	case pgsql.XmlType:
		return TEXTAREA(h.Class("xml"))
	case pgsql.HtmlType:
		return TEXTAREA(h.Class("html"))
	case pgsql.IntType:
		return INPUT(h.Attr("type", "number"))
	case pgsql.UuidType:
		if in.ForeignKey != nil {
			return INPUT(h.Attr("type", "text", "fkey", in.ForeignKey.Table.Name), h.Class("foreign-key"))
		}
		return INPUT(h.Attr("type", "text"))
	case pgsql.DateType:
		return INPUT(h.Attr("type", "text"), h.Class("date"))
	case pgsql.TimeType:
		return INPUT(h.Attr("type", "time"))
	}
	return INPUT(h.Attr("type", "text"))
}
Example #2
0
func (ø *TableForm) getElement(in *pgsql.Field) (out *h.Element) {
	if in.Selection != nil {
		ø.afterCreation = append(ø.afterCreation, func(tf *TableForm) {
			sell := []interface{}{}
			for _, ss := range in.Selection {
				sell = append(sell, ss)
			}
			tf.Selection(in.Name, sell...)
		})
		return SELECT()
	}
	if pgsql.IsVarChar(in.Type) {
		return INPUT(h.Attr("type", "text"))
	}

	if in.Type == pgsql.BoolType {
		return SELECT(
			OPTION(h.Attr("value", "true"), "true"),
			OPTION(h.Attr("value", "false"), "false"),
		)
	}

	switch in.Type {
	case pgsql.TextType:
		return TEXTAREA()
	case pgsql.XmlType:
		return TEXTAREA(h.Class("xml"))
	case pgsql.HtmlType:
		return TEXTAREA(h.Class("html"))
	case pgsql.UuidType:
		if in.ForeignKey != nil {
			return INPUT(h.Attr("type", "text", "fkey", in.ForeignKey.Table.Name), h.Class("foreign-key"))
		}
		return INPUT(h.Attr("type", "text"))
	case pgsql.IntType:
		return INPUT(h.Attr("type", "number"))
	case pgsql.DateType:
		return INPUT(h.Class("date"), h.Attr("type", "text"))
	case pgsql.TimeType:
		return INPUT(h.Attr("type", "time"))
	}
	return INPUT(h.Attr("type", "text"))

	/*
	 input[type="password"]:focus,
	 input[type="datetime"]:focus,
	 input[type="datetime-local"]:focus,
	 input[type="date"]:focus,
	 input[type="month"]:focus,
	 input[type="time"]:focus,
	 input[type="week"]:focus,
	 input[type="number"]:focus,
	 input[type="email"]:focus,
	 input[type="url"]:focus,
	 input[type="search"]:focus,
	 input[type="tel"]:focus,
	 input[type="color"]:focus,
	 .uneditable-input:focus
	*/

}