diff --git a/dev/full/data.js b/dev/full/data.js index a0df6982..a33966b2 100644 --- a/dev/full/data.js +++ b/dev/full/data.js @@ -25,7 +25,7 @@ module.exports = { user.type = fakerator.random.arrayElement(["personal", "business"]); user.bio = fakerator.lorem.paragraph(); let dob = fakerator.date.past(40, "1998-01-01"); - user.dob = dob.valueOf(); + user.dob = /*fecha.format(dob, "YYYY.MM.DD");*/ dob.valueOf(); user.time = fecha.format(new Date(), "hh:mm:ss"); user.age = fecha.format(new Date().getFullYear() - dob, "YY"); user.rank = fakerator.random.number(1, 10); diff --git a/dev/full/schema.js b/dev/full/schema.js index 14a81a99..536f4202 100644 --- a/dev/full/schema.js +++ b/dev/full/schema.js @@ -96,6 +96,7 @@ module.exports = { label: "Date", model: "dob", styleClasses: "half-width" + //format: "YYYY.MM.DD HH:mm:ss" }, { type: "input", inputType: "datetime", diff --git a/src/fields/core/fieldInput.vue b/src/fields/core/fieldInput.vue index c6882162..f4a0fbf5 100644 --- a/src/fields/core/fieldInput.vue +++ b/src/fields/core/fieldInput.vue @@ -48,29 +48,57 @@ this.value = event.target.files; } }, + formatValueToField(value) { if (value != null) { + let dt; switch(this.schema.inputType){ case "date": - return fecha.format(value, "YYYY-MM-DD"); + dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value); + return fecha.format(dt, "YYYY-MM-DD"); case "datetime": - return fecha.format(value, "YYYY-MM-DD HH:mm:ss"); + dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value); + return fecha.format(dt, "YYYY-MM-DD HH:mm:ss"); case "datetime-local": - return fecha.format(value, "YYYY-MM-DDTHH:mm:ss"); + dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value); + return fecha.format(dt, "YYYY-MM-DDTHH:mm:ss"); } } return value; }, + formatValueToModel(value) { if (value != null) { + let m; switch (this.schema.inputType){ case "date": - return fecha.parse(value, "YYYY-MM-DD"); + m = fecha.parse(value, "YYYY-MM-DD"); + if (m !== false) { + if (this.schema.format) + value = fecha.format(m, this.schema.format); + else + value = m.valueOf(); + } + break; case "datetime": - return fecha.parse(value, "YYYY-MM-DD HH:mm:ss"); + m = fecha.parse(value, "YYYY-MM-DD HH:mm:ss"); + if (m !== false) { + if (this.schema.format) + value = fecha.format(m, this.schema.format); + else + value = m.valueOf(); + } + break; case "datetime-local": - return fecha.parse(value, "YYYY-MM-DDTHH:mm:ss"); + m = fecha.parse(value, "YYYY-MM-DDTHH:mm:ss"); + if (m !== false) { + if (this.schema.format) + value = fecha.format(m, this.schema.format); + else + value = m.valueOf(); + } + break; case "number": return Number(value); }