Skip to content

Commit c0549f2

Browse files
authored
fix: Update control input IDs on schema change (#2307)
This commit updates the IDs of all controls if the schema prop handed over to JSON Forms changes. closes #2213
1 parent 0ee8bf2 commit c0549f2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

packages/angular/src/library/abstract-control.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
JsonFormsState,
3030
JsonSchema,
3131
OwnPropsOfControl,
32+
removeId,
3233
StatePropsOfControl,
3334
} from '@jsonforms/core';
3435
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
@@ -148,6 +149,7 @@ export abstract class JsonFormsAbstractControl<
148149
if (this.subscription) {
149150
this.subscription.unsubscribe();
150151
}
152+
removeId(this.id);
151153
}
152154

153155
isEnabled(): boolean {

packages/react/src/JsonForms.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ export class JsonFormsDispatchRenderer extends React.Component<
7777
}
7878
}
7979

80+
componentDidUpdate(prevProps: JsonFormsProps) {
81+
if (prevProps.schema !== this.props.schema) {
82+
removeId(this.state.id);
83+
this.setState({
84+
id: isControl(this.props.uischema)
85+
? createId(this.props.uischema.scope)
86+
: undefined,
87+
});
88+
}
89+
}
90+
8091
render() {
8192
const {
8293
schema,

packages/vue/src/jsonFormsCompositions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
mapStateToLabelProps,
3737
LabelElement,
3838
Categorization,
39+
isControl,
3940
} from '@jsonforms/core';
4041
import {
4142
PropType,
@@ -45,6 +46,7 @@ import {
4546
onBeforeMount,
4647
onUnmounted,
4748
ref,
49+
watch,
4850
} from 'vue';
4951

5052
/**
@@ -184,6 +186,21 @@ export function useControl<R, D, P extends {}>(
184186
}
185187
});
186188

189+
watch(
190+
() => (props as unknown as RendererProps).schema,
191+
(newSchema, prevSchem) => {
192+
if (
193+
newSchema !== prevSchem &&
194+
isControl((control.value as any).uischema)
195+
) {
196+
if (id.value) {
197+
removeId(id.value);
198+
}
199+
id.value = createId((control.value as any).uischema.scope);
200+
}
201+
}
202+
);
203+
187204
onUnmounted(() => {
188205
if (id.value) {
189206
removeId(id.value);

0 commit comments

Comments
 (0)