fix: input date only (birth date for now)
This commit is contained in:
parent
2d8c4d5d6a
commit
a92e9ffdc1
2 changed files with 36 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ import useOptionStore from 'src/stores/options';
|
||||||
import {
|
import {
|
||||||
dateFormat,
|
dateFormat,
|
||||||
calculateAge,
|
calculateAge,
|
||||||
|
parseAndFormatDate,
|
||||||
disabledAfterToday,
|
disabledAfterToday,
|
||||||
} from 'src/utils/datetime';
|
} from 'src/utils/datetime';
|
||||||
|
|
||||||
|
|
@ -119,6 +120,7 @@ defineProps<{
|
||||||
v-model="gender"
|
v-model="gender"
|
||||||
:options="optionStore.globalOption.gender"
|
:options="optionStore.globalOption.gender"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<VueDatePicker
|
<VueDatePicker
|
||||||
id="input-birth-date"
|
id="input-birth-date"
|
||||||
for="input-birth-date"
|
for="input-birth-date"
|
||||||
|
|
@ -143,16 +145,33 @@ defineProps<{
|
||||||
<q-input
|
<q-input
|
||||||
id="input-birth-date"
|
id="input-birth-date"
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
|
:mask="
|
||||||
|
birthDate?.toString() === 'Invalid Date' ||
|
||||||
|
birthDate?.toString() === undefined
|
||||||
|
? '##/##/####'
|
||||||
|
: ''
|
||||||
|
"
|
||||||
|
placeholder="DD/MM/YYYY"
|
||||||
:label="$t('formDialogInputBirthDate')"
|
:label="$t('formDialogInputBirthDate')"
|
||||||
:dense="dense"
|
:dense="dense"
|
||||||
outlined
|
outlined
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:model-value="birthDate ? dateFormat(birthDate) : ''"
|
|
||||||
:rules="[
|
:rules="[
|
||||||
(val: string) =>
|
(val: string) =>
|
||||||
!!val || $t('selectValidate') + $t('formDialogInputBirthDate'),
|
!!val || $t('selectValidate') + $t('formDialogInputBirthDate'),
|
||||||
]"
|
]"
|
||||||
|
:model-value="birthDate ? dateFormat(birthDate) : ''"
|
||||||
|
@update:model-value="
|
||||||
|
(v) => {
|
||||||
|
if (v && v.toString().length === 10) {
|
||||||
|
const date = parseAndFormatDate(v);
|
||||||
|
birthDate = date;
|
||||||
|
}
|
||||||
|
if (v && v.toString().length === 0) birthDate = '';
|
||||||
|
}
|
||||||
|
"
|
||||||
>
|
>
|
||||||
|
<!-- v-model="birthDate" -->
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-icon
|
<q-icon
|
||||||
size="xs"
|
size="xs"
|
||||||
|
|
@ -171,7 +190,12 @@ defineProps<{
|
||||||
readonly
|
readonly
|
||||||
:label="$t('formDialogInputAge')"
|
:label="$t('formDialogInputAge')"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:model-value="birthDate ? calculateAge(birthDate) : ''"
|
:model-value="
|
||||||
|
birthDate?.toString() === 'Invalid Date' ||
|
||||||
|
birthDate?.toString() === undefined
|
||||||
|
? ''
|
||||||
|
: calculateAge(birthDate)
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<q-select
|
<q-select
|
||||||
v-if="employee"
|
v-if="employee"
|
||||||
|
|
|
||||||
|
|
@ -103,3 +103,13 @@ export function disabledAfterToday(date: Date) {
|
||||||
today.setHours(0, 0, 0, 0);
|
today.setHours(0, 0, 0, 0);
|
||||||
return date > today;
|
return date > today;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseAndFormatDate(value: string | number | undefined) {
|
||||||
|
if (!value) return;
|
||||||
|
if (value && value.toString().length === 10) {
|
||||||
|
const [year, month, day] = value.toString().split('/');
|
||||||
|
|
||||||
|
return new Date(`${day}/${month}/${year}`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue