-
Notifications
You must be signed in to change notification settings - Fork 416
preserve the form data so when we update the additionalErrors the dat… #2478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e41c15d
a6a21e3
d5218b1
0b979c0
ebe262b
51aa0bc
b27ce7f
87bfaa6
e413248
7bde214
6f736d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,21 +26,24 @@ import { | |
| defaultMiddleware, | ||
| Middleware, | ||
| JsonFormsSubStates, | ||
| Layout, | ||
| } from '@jsonforms/core'; | ||
| import { JsonFormsChangeEvent, MaybeReadonly } from '../types'; | ||
| import DispatchRenderer from './DispatchRenderer.vue'; | ||
|
|
||
| import type Ajv from 'ajv'; | ||
| import type { ErrorObject } from 'ajv'; | ||
|
|
||
| // TODO fix @typescript-eslint/ban-types | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| const isObject = (elem: any): elem is Object => { | ||
| return elem && typeof elem === 'object'; | ||
| }; | ||
|
|
||
| const EMPTY: ErrorObject[] = reactive([]); | ||
|
|
||
| const createDefaultLayout = (): Layout => ({ | ||
| type: 'VerticalLayout', | ||
| elements: [], | ||
| }); | ||
| const generateUISchema = (schema: JsonSchema) => | ||
| Generate.uiSchema(schema, undefined, undefined, schema) ?? | ||
| createDefaultLayout(); | ||
|
Comment on lines
+39
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is behavior that shouldn't be defined specifically here. If the Generator does not handle this already, we might fix it there for all. |
||
|
|
||
| export default defineComponent({ | ||
| name: 'JsonForms', | ||
| components: { | ||
|
|
@@ -123,13 +126,10 @@ export default defineComponent({ | |
| }, | ||
| emits: ['change'], | ||
| data() { | ||
| const dataToUse = this.data; | ||
| const generatorData = isObject(dataToUse) ? dataToUse : {}; | ||
| const dataToUse = this.data === undefined ? {} : this.data; | ||
| const schemaToUse: JsonSchema = | ||
| this.schema ?? Generate.jsonSchema(generatorData); | ||
| const uischemaToUse = | ||
| this.uischema ?? | ||
| Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse); | ||
| this.schema ?? Generate.jsonSchema(dataToUse); | ||
| const uischemaToUse = this.uischema ?? generateUISchema(schemaToUse); | ||
| const initCore = (): JsonFormsCore => { | ||
| const initialCore = { | ||
| data: dataToUse, | ||
|
|
@@ -189,29 +189,23 @@ export default defineComponent({ | |
| }, | ||
| watch: { | ||
| schema(newSchema) { | ||
| const generatorData = isObject(this.data) ? this.data : {}; | ||
| this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData); | ||
| this.schemaToUse = newSchema ?? Generate.jsonSchema(this.dataToUse); | ||
| if (!this.uischema) { | ||
| this.uischemaToUse = Generate.uiSchema( | ||
| this.schemaToUse, | ||
| undefined, | ||
| undefined, | ||
| this.schemaToUse | ||
| ); | ||
| this.uischemaToUse = generateUISchema(this.schemaToUse); | ||
| } | ||
| }, | ||
| uischema(newUischema) { | ||
| this.uischemaToUse = | ||
| newUischema ?? | ||
| Generate.uiSchema( | ||
| this.schemaToUse, | ||
| undefined, | ||
| undefined, | ||
| this.schemaToUse | ||
| ); | ||
| this.uischemaToUse = newUischema ?? generateUISchema(this.schemaToUse); | ||
| }, | ||
| data(newData) { | ||
| this.dataToUse = newData; | ||
| this.dataToUse = newData === undefined ? {} : newData; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? For instance, we don't do this in React |
||
|
|
||
| if (!this.schema) { | ||
| this.schemaToUse = Generate.jsonSchema(this.dataToUse); | ||
| if (!this.uischema) { | ||
| this.uischemaToUse = generateUISchema(this.schemaToUse); | ||
| } | ||
| } | ||
| }, | ||
| renderers(newRenderers) { | ||
| this.jsonforms.renderers = newRenderers; | ||
|
|
@@ -251,6 +245,9 @@ export default defineComponent({ | |
| ); | ||
| }, | ||
| eventToEmit(newEvent) { | ||
| // update the data so if we change the additionalErrors this won't reset the form data | ||
| this.dataToUse = newEvent.data; | ||
|
|
||
| this.$emit('change', newEvent); | ||
| }, | ||
| i18n: { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that this is introduced to test the new behavior but even if we were to merge it, I don't think the example app use this unrecommended mixed approach. Thus, this should be reverted