@@ -3291,7 +3291,7 @@ describe('Form omitExtraData and liveOmit', () => {
3291
3291
sandbox . restore ( ) ;
3292
3292
} ) ;
3293
3293
3294
- it ( 'should call getUsedFormData when the omitExtraData prop is true and liveOmit is true' , ( ) => {
3294
+ it ( 'should call omitExtraData when the omitExtraData prop is true and liveOmit is true' , ( ) => {
3295
3295
const schema = {
3296
3296
type : 'object' ,
3297
3297
properties : {
@@ -3316,18 +3316,18 @@ describe('Form omitExtraData and liveOmit', () => {
3316
3316
liveOmit,
3317
3317
} ) ;
3318
3318
3319
- sandbox . stub ( comp . ref . current , 'getUsedFormData ' ) . returns ( {
3319
+ sandbox . stub ( comp . ref . current , 'omitExtraData ' ) . returns ( {
3320
3320
foo : '' ,
3321
3321
} ) ;
3322
3322
3323
3323
fireEvent . change ( node . querySelector ( '[type=text]' ) , {
3324
3324
target : { value : 'new' } ,
3325
3325
} ) ;
3326
3326
3327
- sinon . assert . calledOnce ( comp . ref . current . getUsedFormData ) ;
3327
+ sinon . assert . calledOnce ( comp . ref . current . omitExtraData ) ;
3328
3328
} ) ;
3329
3329
3330
- it ( 'should not call getUsedFormData when the omitExtraData prop is true and liveOmit is unspecified' , ( ) => {
3330
+ it ( 'should not call omitExtraData when the omitExtraData prop is true and liveOmit is unspecified' , ( ) => {
3331
3331
const schema = {
3332
3332
type : 'object' ,
3333
3333
properties : {
@@ -3349,19 +3349,19 @@ describe('Form omitExtraData and liveOmit', () => {
3349
3349
omitExtraData,
3350
3350
} ) ;
3351
3351
3352
- sandbox . stub ( comp . ref . current , 'getUsedFormData ' ) . returns ( {
3352
+ sandbox . stub ( comp . ref . current , 'omitExtraData ' ) . returns ( {
3353
3353
foo : '' ,
3354
3354
} ) ;
3355
3355
3356
3356
fireEvent . change ( node . querySelector ( '[type=text]' ) , {
3357
3357
target : { value : 'new' } ,
3358
3358
} ) ;
3359
3359
3360
- sinon . assert . notCalled ( comp . ref . current . getUsedFormData ) ;
3360
+ sinon . assert . notCalled ( comp . ref . current . omitExtraData ) ;
3361
3361
} ) ;
3362
3362
3363
- describe ( 'getUsedFormData ' , ( ) => {
3364
- it ( 'should call getUsedFormData when the omitExtraData prop is true' , ( ) => {
3363
+ describe ( 'omitExtraData on submit ' , ( ) => {
3364
+ it ( 'should call omitExtraData when the omitExtraData prop is true' , ( ) => {
3365
3365
const schema = {
3366
3366
type : 'object' ,
3367
3367
properties : {
@@ -3385,14 +3385,65 @@ describe('Form omitExtraData and liveOmit', () => {
3385
3385
omitExtraData,
3386
3386
} ) ;
3387
3387
3388
- sandbox . stub ( comp . ref . current , 'getUsedFormData ' ) . returns ( {
3388
+ sandbox . stub ( comp . ref . current , 'omitExtraData ' ) . returns ( {
3389
3389
foo : '' ,
3390
3390
} ) ;
3391
3391
3392
3392
fireEvent . submit ( node ) ;
3393
3393
3394
- sinon . assert . calledOnce ( comp . ref . current . getUsedFormData ) ;
3394
+ sinon . assert . calledOnce ( comp . ref . current . omitExtraData ) ;
3395
+ } ) ;
3396
+
3397
+ it ( 'Should call validateFormWithFormData with the current formData if omitExtraData is false' , ( ) => {
3398
+ const omitExtraData = false ;
3399
+ const schema = {
3400
+ type : 'object' ,
3401
+ properties : {
3402
+ foo : { type : 'string' } ,
3403
+ } ,
3404
+ } ;
3405
+ const formData = { foo : 'bar' , baz : 'baz' } ;
3406
+ const formRef = React . createRef ( ) ;
3407
+ const props = {
3408
+ ref : formRef ,
3409
+ schema,
3410
+ formData,
3411
+ omitExtraData : omitExtraData ,
3412
+ } ;
3413
+ const { comp, node } = createFormComponent ( props ) ;
3414
+ sandbox . stub ( comp . ref . current , 'validateFormWithFormData' ) . returns ( {
3415
+ foo : '' ,
3416
+ } ) ;
3417
+ fireEvent . submit ( node ) ;
3418
+ sinon . assert . calledWithMatch ( comp . ref . current . validateFormWithFormData , formData ) ;
3395
3419
} ) ;
3420
+
3421
+ it ( 'Should call validateFormWithFormData with a new formData with only used fields if omitExtraData is true' , ( ) => {
3422
+ const omitExtraData = true ;
3423
+ const schema = {
3424
+ type : 'object' ,
3425
+ properties : {
3426
+ foo : { type : 'string' } ,
3427
+ } ,
3428
+ } ;
3429
+ const formData = { foo : 'bar' , baz : 'baz' } ;
3430
+ const formRef = React . createRef ( ) ;
3431
+ const props = {
3432
+ ref : formRef ,
3433
+ schema,
3434
+ formData,
3435
+ omitExtraData : omitExtraData ,
3436
+ } ;
3437
+ const { comp, node } = createFormComponent ( props ) ;
3438
+ sandbox . stub ( comp . ref . current , 'validateFormWithFormData' ) . returns ( {
3439
+ foo : '' ,
3440
+ } ) ;
3441
+ fireEvent . submit ( node ) ;
3442
+ sinon . assert . calledWithMatch ( comp . ref . current . validateFormWithFormData , { foo : 'bar' } ) ;
3443
+ } ) ;
3444
+ } ) ;
3445
+
3446
+ describe ( 'getUsedFormData' , ( ) => {
3396
3447
it ( 'should just return the single input form value' , ( ) => {
3397
3448
const schema = {
3398
3449
title : 'A single-field form' ,
@@ -4352,6 +4403,58 @@ describe('Form omitExtraData and liveOmit', () => {
4352
4403
} ) ;
4353
4404
4354
4405
describe ( 'validateForm()' , ( ) => {
4406
+ it ( 'Should call validateFormWithFormData with the current formData if omitExtraData is false' , ( ) => {
4407
+ const omitExtraData = false ;
4408
+ const schema = {
4409
+ type : 'object' ,
4410
+ properties : {
4411
+ foo : { type : 'string' } ,
4412
+ } ,
4413
+ } ;
4414
+ const formData = { foo : 'bar' , baz : 'baz' } ;
4415
+ const formRef = React . createRef ( ) ;
4416
+ const props = {
4417
+ ref : formRef ,
4418
+ schema,
4419
+ formData,
4420
+ omitExtraData : omitExtraData ,
4421
+ } ;
4422
+ const { comp } = createFormComponent ( props ) ;
4423
+ sandbox . stub ( comp . ref . current , 'validateFormWithFormData' ) . returns ( {
4424
+ foo : '' ,
4425
+ } ) ;
4426
+ act ( ( ) => {
4427
+ comp . ref . current . validateForm ( ) ;
4428
+ } ) ;
4429
+ sinon . assert . calledWithMatch ( comp . ref . current . validateFormWithFormData , formData ) ;
4430
+ } ) ;
4431
+
4432
+ it ( 'Should call validateFormWithFormData with a new formData with only used fields if omitExtraData is true' , ( ) => {
4433
+ const omitExtraData = true ;
4434
+ const schema = {
4435
+ type : 'object' ,
4436
+ properties : {
4437
+ foo : { type : 'string' } ,
4438
+ } ,
4439
+ } ;
4440
+ const formData = { foo : 'bar' , baz : 'baz' } ;
4441
+ const formRef = React . createRef ( ) ;
4442
+ const props = {
4443
+ ref : formRef ,
4444
+ schema,
4445
+ formData,
4446
+ omitExtraData : omitExtraData ,
4447
+ } ;
4448
+ const { comp } = createFormComponent ( props ) ;
4449
+ sandbox . stub ( comp . ref . current , 'validateFormWithFormData' ) . returns ( {
4450
+ foo : '' ,
4451
+ } ) ;
4452
+ act ( ( ) => {
4453
+ comp . ref . current . validateForm ( ) ;
4454
+ } ) ;
4455
+ sinon . assert . calledWithMatch ( comp . ref . current . validateFormWithFormData , { foo : 'bar' } ) ;
4456
+ } ) ;
4457
+
4355
4458
it ( 'Should update state when data updated from invalid to valid' , ( ) => {
4356
4459
const ref = createRef ( ) ;
4357
4460
const props = {
0 commit comments