@@ -65,6 +65,7 @@ export interface JsonFormsCore {
65
65
schema : JsonSchema ;
66
66
uischema : UISchemaElement ;
67
67
errors ?: ErrorObject [ ] ;
68
+ additionalErrors ?: ErrorObject [ ] ;
68
69
validator ?: ValidateFunction ;
69
70
ajv ?: Ajv ;
70
71
validationMode ?: ValidationMode ;
@@ -78,6 +79,7 @@ const initState: JsonFormsCore = {
78
79
validator : undefined ,
79
80
ajv : undefined ,
80
81
validationMode : 'ValidateAndShow' ,
82
+ additionalErrors : [ ]
81
83
} ;
82
84
83
85
const reuseAjvForSchema = ( ajv : Ajv , schema : JsonSchema ) : Ajv => {
@@ -133,6 +135,23 @@ const hasValidationModeOption = (option: any): option is InitActionOptions => {
133
135
return false ;
134
136
} ;
135
137
138
+ const hasAdditionalErrorsOption = ( option : any ) : option is InitActionOptions => {
139
+ if ( option ) {
140
+ return option . additionalErrors !== undefined ;
141
+ }
142
+ return false ;
143
+ } ;
144
+
145
+ const getAdditionalErrors = (
146
+ state : JsonFormsCore ,
147
+ action ?: InitAction | UpdateCoreAction
148
+ ) : ErrorObject [ ] => {
149
+ if ( action && hasAdditionalErrorsOption ( action . options ) ) {
150
+ return action . options . additionalErrors ;
151
+ }
152
+ return state . additionalErrors ;
153
+ } ;
154
+
136
155
// tslint:disable-next-line: cyclomatic-complexity
137
156
export const coreReducer : Reducer < JsonFormsCore , CoreActions > = (
138
157
state = initState ,
@@ -145,12 +164,14 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
145
164
const validationMode = getValidationMode ( state , action ) ;
146
165
const v = validationMode === 'NoValidation' ? undefined : thisAjv . compile ( action . schema ) ;
147
166
const e = validate ( v , action . data ) ;
167
+ const additionalErrors = getAdditionalErrors ( state , action ) ;
148
168
149
169
return {
150
170
...state ,
151
171
data : action . data ,
152
172
schema : action . schema ,
153
173
uischema : action . uischema ,
174
+ additionalErrors,
154
175
errors : e ,
155
176
validator : v ,
156
177
ajv : thisAjv ,
@@ -176,6 +197,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
176
197
} else if ( state . data !== action . data ) {
177
198
errors = validate ( validator , action . data ) ;
178
199
}
200
+ const additionalErrors = getAdditionalErrors ( state , action ) ;
179
201
180
202
const stateChanged =
181
203
state . data !== action . data ||
@@ -184,7 +206,8 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
184
206
state . ajv !== thisAjv ||
185
207
state . errors !== errors ||
186
208
state . validator !== validator ||
187
- state . validationMode !== validationMode
209
+ state . validationMode !== validationMode ||
210
+ state . additionalErrors !== additionalErrors
188
211
return stateChanged
189
212
? {
190
213
...state ,
@@ -195,6 +218,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
195
218
errors : isEqual ( errors , state . errors ) ? state . errors : errors ,
196
219
validator : validator ,
197
220
validationMode : validationMode ,
221
+ additionalErrors
198
222
}
199
223
: state ;
200
224
}
@@ -391,8 +415,11 @@ const getErrorsAt = (
391
415
instancePath : string ,
392
416
schema : JsonSchema ,
393
417
matchPath : ( path : string ) => boolean
394
- ) => ( state : JsonFormsCore ) : ErrorObject [ ] =>
395
- errorsAt ( instancePath , schema , matchPath ) ( state . validationMode === 'ValidateAndHide' ? [ ] : state . errors ) ;
418
+ ) => ( state : JsonFormsCore ) : ErrorObject [ ] => {
419
+ const errors = state . errors ?? [ ] ;
420
+ const additionalErrors = state . additionalErrors ?? [ ] ;
421
+ return errorsAt ( instancePath , schema , matchPath ) ( state . validationMode === 'ValidateAndHide' ? [ ...additionalErrors ] : [ ...errors , ...additionalErrors ] ) ;
422
+ }
396
423
397
424
export const errorAt = ( instancePath : string , schema : JsonSchema ) =>
398
425
getErrorsAt ( instancePath , schema , path => path === instancePath ) ;
0 commit comments