Skip to content

Commit

Permalink
Show alert only if the form is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
maayarosama committed Feb 7, 2024
1 parent b75b102 commit 94063d0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions client/src/components/requests/leaveRequest.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-form ref="form" @submit.prevent="createLeave()">
<v-alert density="compact" class="pa-5 my-5" type="warning">
<v-alert v-if="form?.isValid && isValid" density="compact" class="pa-5 my-5" type="warning">
{{ actualDays.state.value === 0 ? "Actual vacation days requested is zero, Selected days might include weekends or public holidays" : "Actual vacation days requested are " + actualDays.state.value +" days" }}
</v-alert>

Expand Down Expand Up @@ -28,7 +28,7 @@
import { useApi } from '@/hooks'
import type { Api } from '@/types';
import { useAsyncState } from '@vueuse/core';
import { computed, ref, watch } from 'vue';
import { computed, onMounted, ref, watch } from 'vue';
import { ApiClientBase } from '@/clients/api/base';
export default {
Expand Down Expand Up @@ -106,10 +106,16 @@ export default {
const validateDates = (value: string | null): string | boolean => {
if (!startDate.value) return 'Please select start date.';
if (!endDate.value) return 'Please select end date.';
if (endDate.value <= startDate.value) return 'End date must be after start date.';
if (endDate.value < startDate.value) return 'End date must be after start date.';
return true;
};
onMounted(() => {
startDateField.value.validate();
endDateField.value.validate();
})
async function createLeave() {
if (leaveReason.value) {
useAsyncState($api.vacations.create(
Expand Down

0 comments on commit 94063d0

Please sign in to comment.