@@ -49,7 +49,8 @@ function computeDefaults(
49
49
parentDefaults ,
50
50
rootSchema ,
51
51
rawFormData = { } ,
52
- includeUndefinedValues = false
52
+ includeUndefinedValues = false ,
53
+ haveAllFields = false
53
54
) {
54
55
let schema = isObject ( _schema ) ? _schema : { } ;
55
56
const formData = isObject ( rawFormData ) ? rawFormData : { } ;
@@ -76,7 +77,8 @@ function computeDefaults(
76
77
defaults ,
77
78
rootSchema ,
78
79
formData ,
79
- includeUndefinedValues
80
+ includeUndefinedValues ,
81
+ haveAllFields
80
82
) ;
81
83
} else if /* ('dependencies' in schema) {
82
84
const resolvedSchema = resolveDependencies(schema, rootSchema, formData);
@@ -85,19 +87,21 @@ function computeDefaults(
85
87
defaults,
86
88
rootSchema,
87
89
formData,
88
- includeUndefinedValues
90
+ includeUndefinedValues,
91
+ haveAllFields
89
92
);
90
93
} else if */ ( isFixedItems ( schema ) ) {
91
94
defaults = schema . items . map ( ( itemSchema , idx ) => computeDefaults (
92
95
itemSchema ,
93
96
Array . isArray ( parentDefaults ) ? parentDefaults [ idx ] : undefined ,
94
97
rootSchema ,
95
98
formData ,
96
- includeUndefinedValues
99
+ includeUndefinedValues ,
100
+ haveAllFields
97
101
) ) ;
98
102
} else if ( 'oneOf' in schema ) {
99
103
const matchSchema = retrieveSchema (
100
- schema . oneOf [ getMatchingOption ( formData , schema . oneOf , rootSchema ) ] ,
104
+ schema . oneOf [ getMatchingOption ( formData , schema . oneOf , rootSchema , haveAllFields ) ] ,
101
105
rootSchema ,
102
106
formData
103
107
) ;
@@ -115,7 +119,7 @@ function computeDefaults(
115
119
// }
116
120
} else if ( 'anyOf' in schema ) {
117
121
const matchSchema = retrieveSchema (
118
- schema . anyOf [ getMatchingOption ( formData , schema . anyOf , rootSchema ) ] ,
122
+ schema . anyOf [ getMatchingOption ( formData , schema . anyOf , rootSchema , haveAllFields ) ] ,
119
123
rootSchema ,
120
124
formData
121
125
) ;
@@ -151,7 +155,8 @@ function computeDefaults(
151
155
( defaults || { } ) [ key ] ,
152
156
rootSchema ,
153
157
( formData || { } ) [ key ] ,
154
- includeUndefinedValues
158
+ includeUndefinedValues ,
159
+ haveAllFields
155
160
) ;
156
161
if ( includeUndefinedValues || computedDefault !== undefined ) {
157
162
acc [ key ] = computedDefault ;
@@ -167,7 +172,8 @@ function computeDefaults(
167
172
item ,
168
173
rootSchema ,
169
174
{ } ,
170
- includeUndefinedValues
175
+ includeUndefinedValues ,
176
+ haveAllFields
171
177
) ) ;
172
178
}
173
179
@@ -179,7 +185,8 @@ function computeDefaults(
179
185
rootSchema ,
180
186
item ,
181
187
{ } ,
182
- includeUndefinedValues
188
+ includeUndefinedValues ,
189
+ haveAllFields
183
190
) ) ;
184
191
}
185
192
if ( schema . minItems ) {
@@ -194,7 +201,7 @@ function computeDefaults(
194
201
195
202
const fillerEntries = fillObj (
196
203
new Array ( schema . minItems - defaultsLength ) , computeDefaults (
197
- fillerSchema , fillerSchema . defaults , rootSchema , { } , includeUndefinedValues
204
+ fillerSchema , fillerSchema . defaults , rootSchema , { } , includeUndefinedValues , haveAllFields
198
205
)
199
206
) ;
200
207
return defaultEntries . concat ( fillerEntries ) ;
@@ -216,7 +223,8 @@ export default function getDefaultFormState(
216
223
_schema ,
217
224
formData ,
218
225
rootSchema = { } ,
219
- includeUndefinedValues = true
226
+ includeUndefinedValues = true ,
227
+ haveAllFields = false
220
228
) {
221
229
if ( ! isObject ( _schema ) ) {
222
230
throw new Error ( `Invalid schema: ${ _schema } ` ) ;
@@ -228,7 +236,8 @@ export default function getDefaultFormState(
228
236
_schema . default ,
229
237
rootSchema ,
230
238
formData ,
231
- includeUndefinedValues
239
+ includeUndefinedValues ,
240
+ haveAllFields
232
241
) ;
233
242
234
243
if ( typeof formData === 'undefined' ) {
0 commit comments