Skip to content

Commit

Permalink
fix #138. Add format to date inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Jun 2, 2017
1 parent 938f112 commit c82cd9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dev/full/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions dev/full/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ module.exports = {
label: "Date",
model: "dob",
styleClasses: "half-width"
//format: "YYYY.MM.DD HH:mm:ss"
}, {
type: "input",
inputType: "datetime",
Expand Down
40 changes: 34 additions & 6 deletions src/fields/core/fieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c82cd9a

Please sign in to comment.