fix Bug in IsoDateInput that you can write the date
This commit is contained in:
parent
61316dcd9f
commit
51240dd98b
|
@ -5,7 +5,7 @@
|
||||||
:label="label"
|
:label="label"
|
||||||
:value="getDateTime()"
|
:value="getDateTime()"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
v-on:input="dateChanged"
|
v-on:input="dateTimeChanged"
|
||||||
:rules="rules"
|
:rules="rules"
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
|
@ -49,18 +49,18 @@ export default defineComponent({
|
||||||
name: 'IsoDateInput',
|
name: 'IsoDateInput',
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
label: {},
|
label: {},
|
||||||
readonly: {
|
readonly: {
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
default: 'date',
|
default: 'date',
|
||||||
validator: function(value: string) {
|
validator: function(value: string) {
|
||||||
return ['date', 'time', 'datetime'].indexOf(value) !== -1;
|
return ['date', 'time', 'datetime'].indexOf(value) !== -1;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
setup(props: Props, { emit }: { emit: any }) {
|
setup(props: Props, { emit }: { emit: any }) {
|
||||||
function getDateTime() {
|
function getDateTime() {
|
||||||
|
@ -105,9 +105,15 @@ export default defineComponent({
|
||||||
|
|
||||||
function dateChanged(dateString: string) {
|
function dateChanged(dateString: string) {
|
||||||
_date.value = dateString;
|
_date.value = dateString;
|
||||||
console.log('dateChanged', new Date(`${_date.value} ${_time.value}`));
|
console.log(dateString);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
||||||
emit('input', new Date(`${_date.value} ${_time.value}`));
|
if (/^\d{4}-\d\d-\d\d$/.test(dateString)) {
|
||||||
|
console.log('dateChanged', new Date(`${_date.value} ${_time.value}`));
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
|
emit('input', new Date(`${_date.value} ${_time.value}`));
|
||||||
|
} else {
|
||||||
|
console.log('no date');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeChanged(timeString: string) {
|
function timeChanged(timeString: string) {
|
||||||
|
@ -115,9 +121,32 @@ export default defineComponent({
|
||||||
if (_date.value == '') {
|
if (_date.value == '') {
|
||||||
_date.value = date.formatDate(new Date(), 'YYYY-MM-DD');
|
_date.value = date.formatDate(new Date(), 'YYYY-MM-DD');
|
||||||
}
|
}
|
||||||
console.log('timeChanged', new Date(`${_date.value} ${_time.value}`));
|
if (/^\d\d:\d\d$/.test(timeString)) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
console.log('timeChanged', new Date(`${_date.value} ${_time.value}`));
|
||||||
emit('input', new Date(`${_date.value} ${_time.value}`));
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
|
emit('input', new Date(`${_date.value} ${_time.value}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dateTimeChanged(dateTimeString: string) {
|
||||||
|
switch (props.type) {
|
||||||
|
case 'date':
|
||||||
|
dateChanged(dateTimeString);
|
||||||
|
break;
|
||||||
|
case 'time':
|
||||||
|
timeChanged(dateTimeString);
|
||||||
|
break;
|
||||||
|
case 'datetime':
|
||||||
|
const _dateTime = dateTimeString.split(' ');
|
||||||
|
_date.value = _dateTime[0];
|
||||||
|
_time.value = _dateTime[1];
|
||||||
|
console.log(dateTimeString, _dateTime);
|
||||||
|
if (/^\d{4}-\d\d-\d\d \d\d:\d\d$/.test(dateTimeString)) {
|
||||||
|
console.log('dateTimeChanged');
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
|
emit('input', new Date(`${_date.value} ${_time.value}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDate(val: string) {
|
function isDate(val: string) {
|
||||||
|
@ -153,8 +182,9 @@ export default defineComponent({
|
||||||
dateChanged,
|
dateChanged,
|
||||||
rules,
|
rules,
|
||||||
timeChanged,
|
timeChanged,
|
||||||
placeholder
|
placeholder,
|
||||||
|
dateTimeChanged,
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue