@rjsf/core 5.21.1 → 5.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -202,15 +202,18 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
202
202
  const newFormData = { ...formData } as T;
203
203
 
204
204
  let type: RJSFSchema['type'] = undefined;
205
+ let constValue: RJSFSchema['const'] = undefined;
205
206
  let defaultValue: RJSFSchema['default'] = undefined;
206
207
  if (isObject(schema.additionalProperties)) {
207
208
  type = schema.additionalProperties.type;
209
+ constValue = schema.additionalProperties.const;
208
210
  defaultValue = schema.additionalProperties.default;
209
211
  let apSchema = schema.additionalProperties;
210
212
  if (REF_KEY in apSchema) {
211
213
  const { schemaUtils } = registry;
212
214
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[REF_KEY] } as S, formData);
213
215
  type = apSchema.type;
216
+ constValue = apSchema.const;
214
217
  defaultValue = apSchema.default;
215
218
  }
216
219
  if (!type && (ANY_OF_KEY in apSchema || ONE_OF_KEY in apSchema)) {
@@ -219,8 +222,9 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
219
222
  }
220
223
 
221
224
  const newKey = this.getAvailableKey('newKey', newFormData);
225
+ const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
222
226
  // Cast this to make the `set` work properly
223
- set(newFormData as GenericObjectType, newKey, defaultValue ?? this.getDefaultValue(type));
227
+ set(newFormData as GenericObjectType, newKey, newValue);
224
228
 
225
229
  onChange(newFormData);
226
230
  };
@@ -151,7 +151,9 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
151
151
 
152
152
  const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, idSchema, registry);
153
153
  const disabled = Boolean(uiOptions.disabled ?? props.disabled);
154
- const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
154
+ const readonly = Boolean(
155
+ uiOptions.readonly ?? (props.readonly || props.schema.const || props.schema.readOnly || schema.readOnly)
156
+ );
155
157
  const uiSchemaHideError = uiOptions.hideError;
156
158
  // Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
157
159
  const hideError = uiSchemaHideError === undefined ? props.hideError : Boolean(uiSchemaHideError);
@@ -317,6 +319,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
317
319
  schemaUtils.retrieveSchema(isObject(_schema) ? (_schema as S) : ({} as S), formData)
318
320
  )}
319
321
  registry={registry}
322
+ required={required}
320
323
  schema={schema}
321
324
  uiSchema={uiSchema}
322
325
  />
@@ -340,6 +343,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
340
343
  schemaUtils.retrieveSchema(isObject(_schema) ? (_schema as S) : ({} as S), formData)
341
344
  )}
342
345
  registry={registry}
346
+ required={required}
343
347
  schema={schema}
344
348
  uiSchema={uiSchema}
345
349
  />