0
0
Fork 0

Merge pull request 'hotfix: #6917 set right time' (!632) from hotfix-fixVnInputTime into master

Reviewed-on: verdnatura/salix-front#632
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-08-21 07:28:27 +00:00
commit 172c238ac3
1 changed files with 10 additions and 31 deletions

View File

@ -1,5 +1,5 @@
<script setup>
import { watch, computed, ref, nextTick } from 'vue';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { date } from 'quasar';
@ -14,13 +14,13 @@ const props = defineProps({
default: false,
},
});
const initialDate = ref(model.value);
const { t } = useI18n();
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
const dateFormat = 'HH:mm';
const isPopupOpen = ref();
const hover = ref();
const inputRef = ref();
const styleAttrs = computed(() => {
return props.isOutlined
@ -50,7 +50,8 @@ const formattedTime = computed({
}
if (!props.timeOnly) {
const [hh, mm] = time.split(':');
const date = new Date(model.value ? model.value : null);
const date = new Date(model.value ? model.value : initialDate.value);
date.setHours(hh, mm, 0);
time = date?.toISOString();
}
@ -62,37 +63,10 @@ const formattedTime = computed({
function dateToTime(newDate) {
return date.formatDate(new Date(newDate), dateFormat);
}
watch(
() => model.value,
(val) => (formattedTime.value = val),
{ immediate: true }
);
watch(
() => formattedTime.value,
async (val) => {
let position = 3;
const input = inputRef.value?.getNativeElement();
if (!val || !input) return;
let [hh, mm] = val.split(':');
hh = parseInt(hh);
if (hh >= 10 || mm != '00') return;
await nextTick();
await nextTick();
if (!hh) position = 0;
input.setSelectionRange(position, position);
},
{ immediate: true }
);
</script>
<template>
<div @mouseover="hover = true" @mouseleave="hover = false">
<QInput
ref="inputRef"
class="vn-input-time"
mask="##:##"
placeholder="--:--"
@ -102,7 +76,7 @@ watch(
style="min-width: 100px"
:rules="$attrs.required ? [requiredFieldRule] : null"
@click="isPopupOpen = false"
@focus="inputRef.getNativeElement().setSelectionRange(0, 0)"
type="time"
>
<template #append>
<QIcon
@ -149,6 +123,11 @@ watch(
border-style: solid;
}
</style>
<style lang="scss" scoped>
:deep(input[type='time']::-webkit-calendar-picker-indicator) {
display: none;
}
</style>
<i18n>
es:
Open time: Abrir tiempo