11<template lang="pug">
2- json-forms(
3- v-if ="data"
4- :data ="data"
5- :schema ="schema"
6- :uischema ="uischema"
7- :renderers ="renderers"
8- validationMode ="ValidateAndShow"
9- :additionalErrors ="getSchemaValidations"
10- @change ="onChange"
11- )
2+ div
3+ //- pre(v-html="JSON.stringify({ isNew }, null, 2)")
4+ json-forms(
5+ :data ="data"
6+ :schema ="schema"
7+ :uischema ="uischema"
8+ :renderers ="renderers"
9+ validationMode ="ValidateAndShow"
10+ :additionalErrors ="getSchemaValidations"
11+ @change ="onChange"
12+ )
1213</template >
1314
1415<script setup lang="ts">
@@ -49,6 +50,10 @@ const props = defineProps({
4950 type: Object || null ,
5051 default: {},
5152 },
53+ isNew: {
54+ type: Boolean ,
55+ default: false ,
56+ },
5257});
5358
5459const validations = defineModel (' validations' , {
@@ -62,7 +67,7 @@ const data = defineModel('data', {
6267});
6368
6469function onChange(event : JsonFormsChangeEvent ) {
65- data .value = event .data ;
70+ data .value = event .data || {} ;
6671}
6772
6873const getSchemaValidations = computed (() => {
@@ -82,17 +87,25 @@ const getSchemaValidations = computed(() => {
8287 return errorObject ;
8388})
8489
90+ const mode = computed (() => {
91+ return props .isNew ? ' create' : ' update' ;
92+ });
8593
86- const { data : result, pending, error, refresh } = await useHttp (` /management/identities/validation/${props .schemaName } ` , {
94+ const { data : result, pending, error, refresh } = await useHttp < any > (` /management/identities/validation/${props .schemaName } ` , {
8795 method: ' GET' ,
8896});
8997
90- const { data : resultUi, pending : pendingUi, error : errorUi, refresh : refreshUi } = await useHttp (` /management/identities/jsonforms/${props .schemaName } ` , {
98+ const { data : resultUi, pending : pendingUi, error : errorUi, refresh : refreshUi } = await useHttp < any > (` /management/identities/jsonforms/${props .schemaName } ` , {
9199 method: ' GET' ,
100+ params: {
101+ mode ,
102+ },
92103});
93104
94- const schema = ref (result .value .data );
95- const uischema = ref (resultUi .value .data );
105+ // const schema = ref({ ...result.value.data });
106+ // const uischema = ref({ ...resultUi.value.data });
107+ const schema = computed (() => result .value ?.data );
108+ const uischema = computed (() => resultUi .value ?.data );
96109 </script >
97110
98111<style >
0 commit comments