7
7
:label =" label"
8
8
return-object
9
9
:loading =" loading"
10
- :rules =" [validationRule ]"
10
+ :rules =" [is_type_in_project ]"
11
11
>
12
12
<template #item =" { props , item } " >
13
13
<v-list-item v-bind =" props" :title =" null" >
@@ -61,46 +61,51 @@ export default {
61
61
numItems: 5 ,
62
62
total: 0 ,
63
63
lastProjectId: null ,
64
+ error: null ,
65
+ is_type_in_project : () => {
66
+ this .validateType ()
67
+ return this .error
68
+ },
64
69
}
65
70
},
66
71
67
72
computed: {
68
73
selectedIncidentType: {
69
74
get () {
70
- return this .modelValue || null
75
+ if (! this .modelValue ) return null
76
+ if (this .modelValue .id ) {
77
+ return this .items .find ((item ) => item .id === this .modelValue .id ) || null
78
+ }
79
+ // If we only have a name (e.g., from URL params), find by name
80
+ if (this .modelValue .name ) {
81
+ return this .items .find ((item ) => item .name === this .modelValue .name ) || null
82
+ }
83
+ return null
71
84
},
72
85
set (value ) {
73
86
this .$emit (" update:modelValue" , value)
87
+ this .validateType ()
74
88
},
75
89
},
76
- isTypeValid () {
77
- const project_id = this .project ? .id || 0
78
- return this .selectedIncidentType ? .project ? .id == project_id
79
- },
80
- validationRule () {
81
- return this .isTypeValid || " Only types in selected project are allowed"
82
- },
83
90
},
84
91
85
92
watch: {
86
- project: {
87
- handler (newProject ) {
88
- if (newProject? .id !== this .lastProjectId ) {
89
- // Check if we're moving to a valid project (not null)
90
- if (this .lastProjectId ) {
91
- this .lastProjectId = newProject .id
92
- this .resetSelection ()
93
- this .fetchData ()
94
- } else {
95
- // If new project is null/undefined, just update lastProjectId
96
- this .lastProjectId = null
97
- }
98
- }
99
- },
93
+ project () {
94
+ this .validateType ()
95
+ this .fetchData ()
100
96
},
101
97
},
102
98
103
99
methods: {
100
+ validateType () {
101
+ const project_id = this .project ? .id || 0
102
+ const in_project = this .selectedIncidentType ? .project ? .id == project_id
103
+ if (in_project) {
104
+ this .error = true
105
+ } else {
106
+ this .error = " Only types in selected project are allowed"
107
+ }
108
+ },
104
109
clearSelection () {
105
110
this .selectedIncidentType = null
106
111
},
@@ -124,7 +129,10 @@ export default {
124
129
}
125
130
}
126
131
127
- filterOptions = SearchUtils .createParametersFromTableOptions (filterOptions)
132
+ filterOptions = SearchUtils .createParametersFromTableOptions (
133
+ { ... filterOptions },
134
+ " IncidentType"
135
+ )
128
136
129
137
IncidentTypeApi .getAll (filterOptions)
130
138
.then ((response ) => {
0 commit comments