Skip to content

Commit c82cd9a

Browse files
committed
fix #138. Add format to date inputs
1 parent 938f112 commit c82cd9a

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

dev/full/data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
user.type = fakerator.random.arrayElement(["personal", "business"]);
2626
user.bio = fakerator.lorem.paragraph();
2727
let dob = fakerator.date.past(40, "1998-01-01");
28-
user.dob = dob.valueOf();
28+
user.dob = /*fecha.format(dob, "YYYY.MM.DD");*/ dob.valueOf();
2929
user.time = fecha.format(new Date(), "hh:mm:ss");
3030
user.age = fecha.format(new Date().getFullYear() - dob, "YY");
3131
user.rank = fakerator.random.number(1, 10);

dev/full/schema.js

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = {
9696
label: "Date",
9797
model: "dob",
9898
styleClasses: "half-width"
99+
//format: "YYYY.MM.DD HH:mm:ss"
99100
}, {
100101
type: "input",
101102
inputType: "datetime",

src/fields/core/fieldInput.vue

+34-6
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,57 @@
4848
this.value = event.target.files;
4949
}
5050
},
51+
5152
formatValueToField(value) {
5253
if (value != null) {
54+
let dt;
5355
switch(this.schema.inputType){
5456
case "date":
55-
return fecha.format(value, "YYYY-MM-DD");
57+
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
58+
return fecha.format(dt, "YYYY-MM-DD");
5659
case "datetime":
57-
return fecha.format(value, "YYYY-MM-DD HH:mm:ss");
60+
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
61+
return fecha.format(dt, "YYYY-MM-DD HH:mm:ss");
5862
case "datetime-local":
59-
return fecha.format(value, "YYYY-MM-DDTHH:mm:ss");
63+
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
64+
return fecha.format(dt, "YYYY-MM-DDTHH:mm:ss");
6065
}
6166
}
6267
6368
return value;
6469
},
70+
6571
formatValueToModel(value) {
6672
if (value != null) {
73+
let m;
6774
switch (this.schema.inputType){
6875
case "date":
69-
return fecha.parse(value, "YYYY-MM-DD");
76+
m = fecha.parse(value, "YYYY-MM-DD");
77+
if (m !== false) {
78+
if (this.schema.format)
79+
value = fecha.format(m, this.schema.format);
80+
else
81+
value = m.valueOf();
82+
}
83+
break;
7084
case "datetime":
71-
return fecha.parse(value, "YYYY-MM-DD HH:mm:ss");
85+
m = fecha.parse(value, "YYYY-MM-DD HH:mm:ss");
86+
if (m !== false) {
87+
if (this.schema.format)
88+
value = fecha.format(m, this.schema.format);
89+
else
90+
value = m.valueOf();
91+
}
92+
break;
7293
case "datetime-local":
73-
return fecha.parse(value, "YYYY-MM-DDTHH:mm:ss");
94+
m = fecha.parse(value, "YYYY-MM-DDTHH:mm:ss");
95+
if (m !== false) {
96+
if (this.schema.format)
97+
value = fecha.format(m, this.schema.format);
98+
else
99+
value = m.valueOf();
100+
}
101+
break;
74102
case "number":
75103
return Number(value);
76104
}

0 commit comments

Comments
 (0)