fix(z-task-modal): update validation rules for employee timeblock to ensure required fields are enforced correctly

This commit is contained in:
Matej Glasnák committed 2026-01-08 03:49:25 +01:00
1 parent 7361e564d9
commit c72cb9fcdf
1 file changed
+14 -23
@@ -51,7 +51,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, watch, onMounted, nextTick } from 'vue'; import { computed, ref, watch, onMounted, nextTick } from 'vue';
import { useVuelidate } from '@vuelidate/core'; import { useVuelidate } from '@vuelidate/core';
import { helpers } from '@vuelidate/validators'; import { helpers, required } from '@vuelidate/validators';
import { useEmployeeTimeline } from '@/plugins/tm@_utils/useEmployeeTimeline'; import { useEmployeeTimeline } from '@/plugins/tm@_utils/useEmployeeTimeline';
import { import {
timeblockToDateRange, timeblockToDateRange,
@@ -141,38 +141,29 @@ const timeRangeValid = (value: any, siblings: any) => {
// Custom validator: field is required when start OR end time is filled // Custom validator: field is required when start OR end time is filled
// Uses siblings to check the current state of all fields // Uses siblings to check the current state of all fields
const requiredWhenHasTime = (value: any, siblings: any) => { // const requiredWhenHasTime = (value: any, siblings: any) => {
// Check if timeblock has any TIME data (start or end time) // // Check if timeblock has any TIME data (start or end time)
const hasStart = !!siblings.starts_at_time; // const hasStart = !!siblings.starts_at_time;
const hasEnd = !!siblings.ends_at_time; // const hasEnd = !!siblings.ends_at_time;
const hasAnyTimeData = hasStart || hasEnd; // const hasAnyTimeData = hasStart || hasEnd;
// If no time data, no validation needed // // If no time data, no validation needed
if (!hasAnyTimeData) return true; // if (!hasAnyTimeData) return true;
// When time data exists, field must have value (not null, undefined, or empty string) // // When time data exists, field must have value (not null, undefined, or empty string)
return value !== null && value !== undefined && value !== ''; // return value !== null && value !== undefined && value !== '';
}; // };
// Vuelidate rules - if start OR end is filled, all three fields are required // Vuelidate rules - if start OR end is filled, all three fields are required
const rules = { const rules = {
date: { date: {
requiredWhenHasTime: helpers.withMessage( requiredWhenHasTime: helpers.withMessage('Vyberte dátum', required),
'Vyberte dátum',
requiredWhenHasTime,
),
}, },
starts_at_time: { starts_at_time: {
requiredWhenHasTime: helpers.withMessage( requiredWhenHasTime: helpers.withMessage('Zadajte začiatok', required),
'Zadajte začiatok',
requiredWhenHasTime,
),
}, },
ends_at_time: { ends_at_time: {
requiredWhenHasTime: helpers.withMessage( requiredWhenHasTime: helpers.withMessage('Zadajte koniec', required),
'Zadajte koniec',
requiredWhenHasTime,
),
timeRangeValid: helpers.withMessage( timeRangeValid: helpers.withMessage(
'Koniec musí byť po začiatku', 'Koniec musí byť po začiatku',
timeRangeValid, timeRangeValid,