|
18 | 18 | > |
19 | 19 | <div v-if="!Object.keys(sections).length" class="form-section"> |
20 | 20 | <div class="edit-title">{{ createTitle(form) }}</div> |
21 | | - <div v-for="(fieldInfo, fieldName) in filterInSection(true, schema.properties)"> |
| 21 | + <div v-for="(fieldInfo, fieldName) in filterInSection(true, itemSchema.properties)"> |
22 | 22 | <FormField |
23 | 23 | v-if="allExcludeFields.indexOf(fieldName) === -1 && !props.readOnly && !fieldInfo.readOnly" |
24 | 24 | :fieldName="fieldName" |
25 | | - :schema="schema" |
| 25 | + :schema="itemSchema" |
26 | 26 | :form="form" |
27 | 27 | :formServerErrors="formServerErrors" |
28 | 28 | :ref="el => fieldsRef[fieldName] = el" |
|
34 | 34 | <ReadOnlyField |
35 | 35 | v-else-if="allExcludeFields.indexOf(fieldName) === -1 && (props.readOnly || fieldInfo.readOnly)" |
36 | 36 | :fieldName="fieldName" |
37 | | - :schema="schema" |
| 37 | + :schema="itemSchema" |
38 | 38 | :value="form[fieldName]" |
39 | 39 | > |
40 | 40 | <template v-for="(_, name) in $slots" v-slot:[name]="data"> |
|
49 | 49 | <FormField |
50 | 50 | v-if="allExcludeFields.indexOf(fieldName) === -1 && !props.readOnly" |
51 | 51 | :fieldName="fieldName" |
52 | | - :schema="schema" |
| 52 | + :schema="itemSchema" |
53 | 53 | :form="form" |
54 | 54 | :formServerErrors="formServerErrors" |
55 | 55 | :ref="el => fieldsRef[fieldName] = el" |
|
60 | 60 | </FormField> |
61 | 61 | <ReadOnlyField v-else-if="allExcludeFields.indexOf(fieldName) === -1 && props.readOnly" |
62 | 62 | :fieldName="fieldName" |
63 | | - :schema="schema" |
| 63 | + :schema="itemSchema" |
64 | 64 | :value="form[fieldName]" |
65 | 65 | > |
66 | 66 | <template v-for="(_, name) in $slots" v-slot:[name]="data"> |
|
69 | 69 | </ReadOnlyField> |
70 | 70 | </div> |
71 | 71 | </div> |
72 | | - <div v-for="(_, fieldName) in filterInSection(false, schema.properties)"> |
| 72 | + <div v-for="(_, fieldName) in filterInSection(false, itemSchema.properties)"> |
73 | 73 | <FormField |
74 | 74 | v-if="allExcludeFields.indexOf(fieldName) === -1 && !props.readOnly" |
75 | 75 | :fieldName="fieldName" |
76 | | - :schema="schema" |
| 76 | + :schema="itemSchema" |
77 | 77 | :form="form" |
78 | 78 | :formServerErrors="formServerErrors" |
79 | 79 | :noLabel="true" |
|
85 | 85 | </FormField> |
86 | 86 | <ReadOnlyField v-else-if="allExcludeFields.indexOf(fieldName) === -1 && props.readOnly" |
87 | 87 | :fieldName="fieldName" |
88 | | - :schema="schema" |
| 88 | + :schema="itemSchema" |
89 | 89 | :value="form[fieldName]" |
90 | 90 | > |
91 | 91 | <template v-for="(_, name) in $slots" v-slot:[name]="data"> |
@@ -133,18 +133,20 @@ import ReadOnlyField from "~/components/generic/ReadOnlyField.vue"; |
133 | 133 | import BackButton from "~/components/generic/BackButton.vue"; |
134 | 134 | import {ElNotification} from 'element-plus' |
135 | 135 | import {useI18n} from "vue-i18n"; |
| 136 | +import {storeToRefs} from "pinia"; |
136 | 137 |
|
137 | 138 | const {t} = useI18n(); |
138 | 139 | const {$axios} = useNuxtApp(); |
139 | 140 | const itemsStore = useItemsStore() |
140 | 141 | const router = useRouter() |
141 | | -const schema = ref({}) |
142 | 142 | const deleteDialogVisible = ref(false) |
143 | 143 | const form = ref({}) |
144 | 144 | const formServerErrors = ref({}) |
145 | 145 | const formRules = ref({}) |
146 | 146 | const formRef = ref() |
147 | 147 | const fieldsRef = ref({}) |
| 148 | +const {schema} = storeToRefs(itemsStore) |
| 149 | +const itemSchema = ref({}) |
148 | 150 |
|
149 | 151 | const emit = defineEmits(['submitFormStart', 'submitFormEnd']) |
150 | 152 | defineExpose({submitForm, form}) |
@@ -242,20 +244,20 @@ const allExcludeFields = computed(() => { |
242 | 244 | }) |
243 | 245 | async function initData() { |
244 | 246 | itemsStore.loading = true |
245 | | - schema.value = await itemsStore.getSchemaDef($axios, props.apiUrl) |
| 247 | + itemSchema.value = await itemsStore.getSchemaDef($axios, props.apiUrl) |
246 | 248 | itemsStore.loading = false |
247 | 249 | } |
248 | 250 |
|
249 | 251 | await initData() |
250 | 252 |
|
251 | 253 |
|
252 | 254 | // Initialize form |
253 | | -for (const [fieldName, fieldInfo] of Object.entries(schema.value.properties)) { |
| 255 | +for (const [fieldName, fieldInfo] of Object.entries(itemSchema.value.properties)) { |
254 | 256 | if (allExcludeFields.value.indexOf(fieldName) === -1) { |
255 | 257 | form.value[fieldName] = undefined |
256 | 258 | formServerErrors.value[fieldName] = undefined |
257 | 259 | formRules.value[fieldName] = [] |
258 | | - if (schema.value.required.indexOf(fieldName) !== -1) { |
| 260 | + if (itemSchema.value.required.indexOf(fieldName) !== -1) { |
259 | 261 | formRules.value[fieldName].push({required: true, message: `Please enter ${fieldName}`, trigger: 'blur'}) |
260 | 262 | } |
261 | 263 | } |
|
0 commit comments