Skip to content

Commit

Permalink
fixes #480 - dates are always passed to "date" and "datetime-local" e…
Browse files Browse the repository at this point in the history
…lements using the standard format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss), and "datetime" elements are converted into "datetime-local" (datetime is deprecated/obsolete).
  • Loading branch information
zoul0813 committed Dec 10, 2018
1 parent a484031 commit db3413f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/fields/core/fieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.wrapper(v-attributes="'wrapper'")
input.form-control(
:id="getFieldID(schema)",
:type="schema.inputType.toLowerCase()",
:type="inputType",
:value="value",
@input="onInput",
@blur="onBlur",
Expand Down Expand Up @@ -53,6 +53,16 @@ const DATETIME_FORMATS = {
export default {
mixins: [abstractField],
computed: {
inputType() {
if(this.schema && this.schema.inputType === "datetime") {
// convert "datetime" to "datetime-local" (datetime deprecated in favor of "datetime-local")
// ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime
return "datetime-local";
}
return this.schema.inputType;
}
},
methods: {
formatValueToModel(value) {
if (value != null) {
Expand All @@ -71,6 +81,15 @@ export default {
return value;
},
formatValueToField(value) {
switch(this.schema.inputType.toLowerCase()) {
case "date":
case "datetime":
case "datetime-local":
return this.formatDatetimeValueToField(value);
}
return value;
},
formatDatetimeToModel(newValue, oldValue) {
let defaultFormat = DATETIME_FORMATS[this.schema.inputType.toLowerCase()];
let m = fecha.parse(newValue, defaultFormat);
Expand All @@ -83,6 +102,17 @@ export default {
}
this.updateModelValue(newValue, oldValue);
},
formatDatetimeValueToField(value) {
let defaultFormat = DATETIME_FORMATS[this.schema.inputType.toLowerCase()];
let m = value;
if(!isNumber(value)) {
m = fecha.parse(value, defaultFormat);
}
if(m !== false) {
return fecha.format(m, defaultFormat);
}
return value;
},
formatNumberToModel(newValue, oldValue) {
if (!isNumber(newValue)) {
newValue = NaN;
Expand Down

0 comments on commit db3413f

Please sign in to comment.