@@ -31,6 +31,7 @@ import {
3131import isMultiSelect from './isMultiSelect' ;
3232import retrieveSchema , { resolveDependencies } from './retrieveSchema' ;
3333import isConstant from '../isConstant' ;
34+ import { JSONSchema7Object } from 'json-schema' ;
3435
3536/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
3637 */
@@ -319,10 +320,13 @@ export function getObjectDefaults<T = any, S extends StrictRJSFSchema = RJSFSche
319320 experimental_defaultFormStateBehavior ?. allOf === 'populateDefaults' && ALL_OF_KEY in schema
320321 ? retrieveSchema < T , S , F > ( validator , schema , rootSchema , formData )
321322 : schema ;
323+ const parentConst = retrievedSchema [ CONST_KEY ] ;
322324 const objectDefaults = Object . keys ( retrievedSchema . properties || { } ) . reduce (
323325 ( acc : GenericObjectType , key : string ) => {
324326 const propertySchema = get ( retrievedSchema , [ PROPERTIES_KEY , key ] ) ;
325- const hasConst = isObject ( propertySchema ) && CONST_KEY in propertySchema ;
327+ // Check if the parent schema has a const property defined, then we should always return the computedDefault since it's coming from the const.
328+ const hasParentConst = isObject ( parentConst ) && ( parentConst as JSONSchema7Object ) [ key ] !== undefined ;
329+ const hasConst = ( isObject ( propertySchema ) && CONST_KEY in propertySchema ) || hasParentConst ;
326330 // Compute the defaults for this node, with the parent defaults we might
327331 // have from a previous run: defaults[key].
328332 const computedDefault = computeDefaults < T , S , F > ( validator , propertySchema , {
0 commit comments