mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 06:20:21 +00:00
fix(z-task-modal): update validation rules for employee timeblock to ensure required fields are enforced correctly
This commit is contained in:
1 parent
7361e564d9
commit
c72cb9fcdf
1 file changed
+14
-23
@@ -51,7 +51,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch, onMounted, nextTick } from 'vue';
|
||||
import { useVuelidate } from '@vuelidate/core';
|
||||
import { helpers } from '@vuelidate/validators';
|
||||
import { helpers, required } from '@vuelidate/validators';
|
||||
import { useEmployeeTimeline } from '@/plugins/tm@_utils/useEmployeeTimeline';
|
||||
import {
|
||||
timeblockToDateRange,
|
||||
@@ -141,38 +141,29 @@ const timeRangeValid = (value: any, siblings: any) => {
|
||||
|
||||
// Custom validator: field is required when start OR end time is filled
|
||||
// Uses siblings to check the current state of all fields
|
||||
const requiredWhenHasTime = (value: any, siblings: any) => {
|
||||
// Check if timeblock has any TIME data (start or end time)
|
||||
const hasStart = !!siblings.starts_at_time;
|
||||
const hasEnd = !!siblings.ends_at_time;
|
||||
const hasAnyTimeData = hasStart || hasEnd;
|
||||
// const requiredWhenHasTime = (value: any, siblings: any) => {
|
||||
// // Check if timeblock has any TIME data (start or end time)
|
||||
// const hasStart = !!siblings.starts_at_time;
|
||||
// const hasEnd = !!siblings.ends_at_time;
|
||||
// const hasAnyTimeData = hasStart || hasEnd;
|
||||
|
||||
// If no time data, no validation needed
|
||||
if (!hasAnyTimeData) return true;
|
||||
// // If no time data, no validation needed
|
||||
// if (!hasAnyTimeData) return true;
|
||||
|
||||
// When time data exists, field must have value (not null, undefined, or empty string)
|
||||
return value !== null && value !== undefined && value !== '';
|
||||
};
|
||||
// // When time data exists, field must have value (not null, undefined, or empty string)
|
||||
// return value !== null && value !== undefined && value !== '';
|
||||
// };
|
||||
|
||||
// Vuelidate rules - if start OR end is filled, all three fields are required
|
||||
const rules = {
|
||||
date: {
|
||||
requiredWhenHasTime: helpers.withMessage(
|
||||
'Vyberte dátum',
|
||||
requiredWhenHasTime,
|
||||
),
|
||||
requiredWhenHasTime: helpers.withMessage('Vyberte dátum', required),
|
||||
},
|
||||
starts_at_time: {
|
||||
requiredWhenHasTime: helpers.withMessage(
|
||||
'Zadajte začiatok',
|
||||
requiredWhenHasTime,
|
||||
),
|
||||
requiredWhenHasTime: helpers.withMessage('Zadajte začiatok', required),
|
||||
},
|
||||
ends_at_time: {
|
||||
requiredWhenHasTime: helpers.withMessage(
|
||||
'Zadajte koniec',
|
||||
requiredWhenHasTime,
|
||||
),
|
||||
requiredWhenHasTime: helpers.withMessage('Zadajte koniec', required),
|
||||
timeRangeValid: helpers.withMessage(
|
||||
'Koniec musí byť po začiatku',
|
||||
timeRangeValid,
|
||||
|
||||
Reference in new issue
Block a user