diff --git a/src/components/Form.js b/src/components/Form.js index 88d92f096f..874296f1a6 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -40,7 +40,6 @@ export default class Form extends Component { const mustValidate = edit && !props.noValidate && liveValidate; const { definitions } = schema; const formData = getDefaultFormState(schema, props.formData, definitions); - const retrievedSchema = retrieveSchema(schema, definitions, formData); const { errors, errorSchema } = mustValidate ? this.validate(formData, schema) @@ -49,11 +48,10 @@ export default class Form extends Component { errorSchema: state.errorSchema || {}, }; const idSchema = toIdSchema( - retrievedSchema, - uiSchema["ui:rootFieldId"], + schema, + uiSchema["ui:rootFieldId"] || props.idPrefix, definitions, - formData, - props.idPrefix + formData ); return { schema, @@ -102,7 +100,17 @@ export default class Form extends Component { onChange = (formData, newErrorSchema) => { const mustValidate = !this.props.noValidate && this.props.liveValidate; - let state = { formData }; + const { schema, uiSchema } = this.state; + const { definitions } = schema; + let state = { + formData, + idSchema: toIdSchema( + schema, + uiSchema["ui:rootFieldId"] || this.props.idPrefix, + definitions, + formData + ), + }; if (mustValidate) { const { errors, errorSchema } = this.validate(formData); state = { ...state, errors, errorSchema }; diff --git a/src/components/fields/ArrayField.js b/src/components/fields/ArrayField.js index 5d0ce1463b..5cf75ad745 100644 --- a/src/components/fields/ArrayField.js +++ b/src/components/fields/ArrayField.js @@ -12,7 +12,6 @@ import { allowAdditionalItems, optionsList, retrieveSchema, - toIdSchema, getDefaultRegistry, } from "../../utils"; @@ -368,7 +367,6 @@ class ArrayField extends Component { registry = getDefaultRegistry(), onBlur, onFocus, - idPrefix, rawErrors, } = this.props; const title = schema.title === undefined ? name : schema.title; @@ -380,14 +378,7 @@ class ArrayField extends Component { items: formData.map((item, index) => { const itemSchema = retrieveSchema(schema.items, definitions, item); const itemErrorSchema = errorSchema ? errorSchema[index] : undefined; - const itemIdPrefix = idSchema.$id + "_" + index; - const itemIdSchema = toIdSchema( - itemSchema, - itemIdPrefix, - definitions, - item, - idPrefix - ); + const itemIdSchema = idSchema[index]; return this.renderArrayFieldItem({ index, canMoveUp: index > 0, @@ -510,7 +501,6 @@ class ArrayField extends Component { uiSchema, formData, errorSchema, - idPrefix, idSchema, name, required, @@ -551,14 +541,7 @@ class ArrayField extends Component { const itemSchema = additional ? retrieveSchema(schema.additionalItems, definitions, item) : itemSchemas[index]; - const itemIdPrefix = idSchema.$id + "_" + index; - const itemIdSchema = toIdSchema( - itemSchema, - itemIdPrefix, - definitions, - item, - idPrefix - ); + const itemIdSchema = idSchema[index]; const itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) @@ -592,7 +575,7 @@ class ArrayField extends Component { rawErrors, }; - // Check if a custom template template was passed in + // check if a custom template template was passed in const Template = ArrayFieldTemplate || DefaultFixedArrayFieldTemplate; return