Files
axp-ui/src/components/FieldDate.vue
T

40 lines
950 B
Vue
Raw Normal View History

2023-09-20 14:09:22 +03:00
<script lang="ts">
import type { TUiFieldInputProps, TUiFieldInputEmits } from './FieldInput.vue'
export type TUiFieldDateProps = TUiFieldInputProps<Date>
export type TUiFieldDateEmits = TUiFieldInputEmits
</script>
2023-07-11 10:38:21 +03:00
<script setup lang="ts">
import { computed } from 'vue'
import { cFieldsSchema, getDateCommonFormat } from 'axp-ts'
2023-09-20 14:09:22 +03:00
import UiFieldInput from './FieldInput.vue'
2023-07-11 10:38:21 +03:00
2023-09-20 14:09:22 +03:00
// Props.
const props = defineProps<TUiFieldDateProps>()
2023-07-11 10:38:21 +03:00
2023-09-20 14:09:22 +03:00
// Emits.
const emit = defineEmits<TUiFieldDateEmits>()
2023-07-11 10:38:21 +03:00
2023-09-20 14:09:22 +03:00
// Etc.
2023-07-11 10:38:21 +03:00
const valueStr = computed({
get: () => {
try {
const value = cFieldsSchema.shape.date.parse(props.modelValue)
2023-09-20 14:09:22 +03:00
return getDateCommonFormat(value)
} catch (e) { }
2023-07-11 10:38:21 +03:00
},
2023-09-20 14:09:22 +03:00
set: val => {
emit('update:error')
2023-07-11 10:38:21 +03:00
try {
const value = cFieldsSchema.shape.date.parse(val)
2023-09-20 14:09:22 +03:00
emit('update:model-value', value)
} catch (e) { }
2023-07-11 10:38:21 +03:00
}
})
</script>
<template>
2023-09-20 14:09:22 +03:00
<ui-field-input :="{ ...props, ...$attrs }" v-model="valueStr" type="date" />
2023-07-11 10:38:21 +03:00
</template>