From cf2f577eca8072937f61a515cd8b7ec58f991b9c Mon Sep 17 00:00:00 2001 From: Lionel Bijaoui Date: Tue, 20 Sep 2016 11:04:16 +0200 Subject: [PATCH] format date related fields values --- src/fields/fieldInput.vue | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/fields/fieldInput.vue b/src/fields/fieldInput.vue index 8ae7145d..5e20fb0c 100644 --- a/src/fields/fieldInput.vue +++ b/src/fields/fieldInput.vue @@ -37,7 +37,35 @@ import abstractField from "./abstractField"; export default { - mixins: [ abstractField ] + mixins: [ abstractField ], + methods: { + formatValueToField(value) { + switch(this.schema.inputType){ + case "date": + return moment(value).format("YYYY-MM-DD"); + case "datetime": + return moment(value).format(); + case "datetime-local": + return moment(value).format("YYYY-MM-DDTHH:mm:ss"); + default: + return value; + } + }, + formatValueToModel(value) { + console.log(this.schema.inputType, typeof value); + if (value != null) { + if (this.schema.inputType === "date" || + this.schema.inputType === "datetime" || + this.schema.inputType === "datetimelocal") { + return new Date(value).getTime(); + }else{ + return value; + } + } else { + return value; + } + } + } };