@@ -216,37 +216,37 @@ export const createValidator = (callback: ValidationCallback, initialData: Recor
216
216
...instanceConfig ,
217
217
}
218
218
219
- const validate = Array . from ( config . validate ?? touched )
219
+ const only = Array . from ( config . only ?? config . validate ?? touched )
220
220
221
221
return {
222
222
...instanceConfig ,
223
223
// Axios has special rules for merging global and local config. We
224
224
// use their merge function here to make sure things like headers
225
225
// merge in an expected way.
226
226
...mergeConfig ( globalConfig , instanceConfig ) ,
227
- validate ,
227
+ only ,
228
228
timeout : config . timeout ?? 5000 ,
229
229
onValidationError : ( response , axiosError ) => {
230
230
[
231
- ...setValidated ( [ ...validated , ...validate ] ) ,
232
- ...setErrors ( merge ( omit ( { ...errors } , validate ) , response . data . errors ) ) ,
231
+ ...setValidated ( [ ...validated , ...only ] ) ,
232
+ ...setErrors ( merge ( omit ( { ...errors } , only ) , response . data . errors ) ) ,
233
233
] . forEach ( ( listener ) => listener ( ) )
234
234
235
235
return config . onValidationError
236
236
? config . onValidationError ( response , axiosError )
237
237
: Promise . reject ( axiosError )
238
238
} ,
239
239
onSuccess : ( response ) => {
240
- setValidated ( [ ...validated , ...validate ] ) . forEach ( ( listener ) => listener ( ) )
240
+ setValidated ( [ ...validated , ...only ] ) . forEach ( ( listener ) => listener ( ) )
241
241
242
242
return config . onSuccess
243
243
? config . onSuccess ( response )
244
244
: response
245
245
} ,
246
246
onPrecognitionSuccess : ( response ) => {
247
247
[
248
- ...setValidated ( [ ...validated , ...validate ] ) ,
249
- ...setErrors ( omit ( { ...errors } , validate ) ) ,
248
+ ...setValidated ( [ ...validated , ...only ] ) ,
249
+ ...setErrors ( omit ( { ...errors } , only ) ) ,
250
250
] . forEach ( ( listener ) => listener ( ) )
251
251
252
252
return config . onPrecognitionSuccess
@@ -294,6 +294,10 @@ export const createValidator = (callback: ValidationCallback, initialData: Recor
294
294
*/
295
295
const validate = ( name ?: string | NamedInputEvent , value ?: unknown , config ?: ValidationConfig ) : void => {
296
296
if ( typeof name === 'undefined' ) {
297
+ const only = Array . from ( config ?. only ?? config ?. validate ?? [ ] )
298
+
299
+ setTouched ( [ ...touched , ...only ] ) . forEach ( ( listener ) => listener ( ) )
300
+
297
301
validator ( config ?? { } )
298
302
299
303
return
0 commit comments