mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 06:20:21 +00:00
fix(z-task-modal): fixed validation logic for employees, at least 1 employee is required
This commit is contained in:
1 parent
f7b81b632f
commit
3f75f9d204
1 file changed
+32
-17
@@ -635,6 +635,8 @@ export default {
|
||||
|
||||
if (!(await this.v$.$validate())) return;
|
||||
if (!employeesValid || !timeblocksValid) return;
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
async handleOnRemoveEmployee() {
|
||||
@@ -757,28 +759,41 @@ export default {
|
||||
this.employeeValidations = [];
|
||||
|
||||
if (this.subtask.id) {
|
||||
if (this.subtask.employee && this.subtask.duration) return;
|
||||
|
||||
this.employeeValidations[0] = {};
|
||||
|
||||
if (!this.subtask.employee_id)
|
||||
this.employeeValidations[0].employee = true;
|
||||
|
||||
if (!this.subtask.duration)
|
||||
this.employeeValidations[0].duration = true;
|
||||
// For existing subtasks, require both employee and duration
|
||||
if (!this.subtask.employee_id || !this.subtask.duration) {
|
||||
this.employeeValidations[0] = {
|
||||
employee: !this.subtask.employee_id,
|
||||
duration: !this.subtask.duration,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// For new subtasks, only validate non-empty employee entries
|
||||
// For new subtasks, require at least one employee with duration
|
||||
let hasValidEmployee = false;
|
||||
|
||||
this.subtask.employees.forEach((employee, index) => {
|
||||
// Skip validation if both id and duration are empty
|
||||
if (!employee.id && !employee.duration) return;
|
||||
if (!employee.id && !employee.duration) {
|
||||
// If this is the first employee and no valid employee exists yet, show validation
|
||||
if (index === 0 && !hasValidEmployee) {
|
||||
this.employeeValidations[index] = {
|
||||
employee: true,
|
||||
duration: true,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Only validate if either id or duration is filled
|
||||
// Validate if either id or duration is filled
|
||||
if (employee.id || employee.duration) {
|
||||
this.employeeValidations[index] = {};
|
||||
this.employeeValidations[index] = {
|
||||
employee: !employee.id,
|
||||
duration: !employee.duration,
|
||||
};
|
||||
|
||||
if (!employee.id) this.employeeValidations[index].employee = true;
|
||||
if (!employee.duration)
|
||||
this.employeeValidations[index].duration = true;
|
||||
// If both id and duration are present, mark as valid
|
||||
if (employee.id && employee.duration) {
|
||||
hasValidEmployee = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -855,7 +870,7 @@ export default {
|
||||
subtask: {
|
||||
handler(val) {
|
||||
if (this.editMode && !this.subtask?.id) {
|
||||
const employees = val.employees.filter(
|
||||
const employees = val?.employees?.filter(
|
||||
(employee) => employee?.id || employee?.duration,
|
||||
) || [{}];
|
||||
|
||||
|
||||
Reference in new issue
Block a user