diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-17 20:56:28 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-17 20:56:28 -0700 |
commit | cc61653bc4cc23e29817a035514adf428607ea84 (patch) | |
tree | d2fff7c89c46e0243330efcf73124e6528699240 | |
parent | be93740b74ad952770725a15a5b024099b1b25ea (diff) |
adding Time input to specify the reflect Value output from int64 type
-rw-r--r-- | management/editor/elements.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/management/editor/elements.go b/management/editor/elements.go index 0792466..b06049d 100644 --- a/management/editor/elements.go +++ b/management/editor/elements.go @@ -37,6 +37,31 @@ func Textarea(fieldName string, p interface{}, attrs map[string]string) []byte { return domElement(e) } +// Time returns the []byte of an <input> HTML element with a label. +// IMPORTANT: +// The `fieldName` argument will cause a panic if it is not exactly the string +// form of the struct field that this editor input is representing +func Time(fieldName string, p interface{}, attrs map[string]string) []byte { + var data string + val := valueFromStructField(fieldName, p) + if val.Int() == 0 { + data = "" + } else { + data = val.String() + } + + e := &element{ + TagName: "input", + Attrs: attrs, + Name: tagNameFromStructField(fieldName, p), + label: attrs["label"], + data: data, + viewBuf: &bytes.Buffer{}, + } + + return domElementSelfClose(e) +} + // File returns the []byte of a <input type="file"> HTML element with a label. // IMPORTANT: // The `fieldName` argument will cause a panic if it is not exactly the string @@ -451,8 +476,6 @@ func tagNameFromStructFieldMulti(name string, i int, post interface{}) string { func valueFromStructField(name string, post interface{}) reflect.Value { field := reflect.Indirect(reflect.ValueOf(post)).FieldByName(name) - fmt.Println(name, field, field.String()) - return field } |