Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HELP] Как ввести дату в инпут вручную? #355

Open
RakAndrey opened this issue Jan 16, 2025 · 0 comments
Open

[HELP] Как ввести дату в инпут вручную? #355

RakAndrey opened this issue Jan 16, 2025 · 0 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@RakAndrey
Copy link

RakAndrey commented Jan 16, 2025

Подскажите как ввести дату в инпут вручную, чтобы она стала отмеченной в календаре?
Метод update не помогает. Пробовал передавать в этот метод и dateToday и selectedDates.
Если в настройках использовать метод onChangeToInput, то в инпут вообще не получается ничего ввести.

К тому же, чтобы на обработчике вызвать метод update, инстанс календаря приходится оборачивать в рефку, чтобы получить к нему доступ на верхнем уровне setup функции. А т.к. в инстансе очень много параметров и большой уровень вложенности, делать этот огромный объект реактивным давольно ресурсозатратно.

<template>
<input type="text" v-maska="maskOptions" placeholder="..____" :value="calendarValue" ref="calendarRef">
</template>

<script setup>
import { vMaska } from "maska/vue"
import { Calendar } from 'vanilla-calendar-pro'
import 'vanilla-calendar-pro/styles/index.css'


// Defines
const emit = defineEmits(['update:modelValue'])
const props = defineProps(['modelValue'])


// Composables
const { formatDate } = useUtils()


// Data
const calendar = ref(null)
const calendarRef = ref(null)
const calendarValue = ref(null)
const calendarOptions = reactive({
    inputMode: true,
    locale: 'ru-Ru',
    onClickDate(self) {
        self.hide()
        emit('update:modelValue', self.context.selectedDates.map(date => formatDate(date)))
    }
})
const maskOptions = reactive({
    mask: '##.##.####',
    onMaska: (detail) => {
        if(detail.completed){
            calendar.value.update({
                dateToday: new Date(detail.masked)
            })
            calendar.value.hide()
        }
    }
})


for(let key in props.options){
    calendarOptions[key] = props.options[key]
}


// Hooks
onMounted(() => {
    if (calendarRef.value){
        calendar.value = new Calendar(calendarRef.value, calendarOptions)
        calendar.value.init()
    }
})

onUpdated(() => {
    calendarValue.value = props.modelValue
})
</script>
@RakAndrey RakAndrey added help wanted Extra attention is needed question Further information is requested labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant