From b6cce74449dfbf28c95ab36832635d41e20011bd Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 13 Sep 2024 23:11:18 +0200 Subject: [PATCH] fix: merge conflicts --- src/components/common/VnInputDate.vue | 53 ++++++++++++++------------- src/components/common/VnInputTime.vue | 6 ++- src/components/common/VnSelect.vue | 12 +++--- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/components/common/VnInputDate.vue b/src/components/common/VnInputDate.vue index 96e47d6d7..7113cadf9 100644 --- a/src/components/common/VnInputDate.vue +++ b/src/components/common/VnInputDate.vue @@ -2,6 +2,7 @@ import { onMounted, watch, computed, ref } from 'vue'; import { date } from 'quasar'; import { useI18n } from 'vue-i18n'; +import { useAttrs } from 'vue'; const model = defineModel({ type: [String, Date] }); const $props = defineProps({ @@ -14,29 +15,19 @@ const $props = defineProps({ default: true, }, }); +import { useValidator } from 'src/composables/useValidator'; +const { validations } = useValidator(); const { t } = useI18n(); -const requiredFieldRule = (val) => !!val || t('globals.fieldRequired'); +const requiredFieldRule = (val) => validations().required($attrs.required, val); const dateFormat = 'DD/MM/YYYY'; const isPopupOpen = ref(); const hover = ref(); const mask = ref(); +const $attrs = useAttrs(); -onMounted(() => { - // fix quasar bug - mask.value = '##/##/####'; -}); - -const styleAttrs = computed(() => { - return $props.isOutlined - ? { - dense: true, - outlined: true, - rounded: true, - } - : {}; -}); +const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])]; const formattedDate = computed({ get() { @@ -48,15 +39,12 @@ const formattedDate = computed({ let newDate; if (value) { // parse input - if (value.includes('/')) { - if (value.length == 6) value = value + new Date().getFullYear(); - if (value.length >= 10) { - if (value.at(2) == '/') value = value.split('/').reverse().join('/'); - value = date.formatDate( - new Date(value).toISOString(), - 'YYYY-MM-DDTHH:mm:ss.SSSZ' - ); - } + if (value.includes('/') && value.length >= 10) { + if (value.at(2) == '/') value = value.split('/').reverse().join('/'); + value = date.formatDate( + new Date(value).toISOString(), + 'YYYY-MM-DDTHH:mm:ss.SSSZ' + ); } const [year, month, day] = value.split('-').map((e) => parseInt(e)); newDate = new Date(year, month - 1, day); @@ -79,12 +67,25 @@ const formattedDate = computed({ const popupDate = computed(() => model.value ? date.formatDate(new Date(model.value), 'YYYY/MM/DD') : model.value ); - +onMounted(() => { + // fix quasar bug + mask.value = '##/##/####'; +}); watch( () => model.value, (val) => (formattedDate.value = val), { immediate: true } ); + +const styleAttrs = computed(() => { + return $props.isOutlined + ? { + dense: true, + outlined: true, + rounded: true, + } + : {}; +});