Skip to content

Commit

Permalink
fix broken date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Onatcer committed Apr 25, 2024
1 parent 6c25c5d commit 023f6b1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions resources/js/Components/Common/DatePicker.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { ref } from 'vue';
import { getLocalizedDayJs } from '@/utils/time';
import dayjs from 'dayjs';
const model = defineModel<string | null>({
default: null,
});
const tempDate = ref(getLocalizedDayJs(model.value).format('YYYY-MM-DD'));
function updateDate(event: Event) {
const target = event.target as HTMLInputElement;
const newValue = target.value;
const newDate = dayjs(newValue);
const newDate = getLocalizedDayJs(newValue);
if (newDate) {
console.log('old', model.value);
model.value = getLocalizedDayJs(model.value)
.set('year', newDate.year())
.set('day', newDate.day())
Expand All @@ -22,25 +22,25 @@ function updateDate(event: Event) {
}
}
const date = computed(() => {
return model.value
? getLocalizedDayJs(model.value).format('YYYY-MM-DD')
: null;
});
const datePicker = ref<HTMLInputElement | null>(null);
function updateTempValue(event: Event) {
const target = event.target as HTMLInputElement;
tempDate.value = target.value;
}
</script>

<template>
<div class="flex items-center justify-center text-muted">
<input
ref="datePicker"
@change="updateDate"
@change="updateTempValue"
@blur="updateDate"
class="bg-input-background border text-white border-input-border rounded-md"
type="date"
id="start"
name="trip-start"
:value="date" />
:value="tempDate" />
</div>
</template>

Expand Down

0 comments on commit 023f6b1

Please sign in to comment.