@@ -1309,7 +1309,6 @@ describe('formly-field', function() {
1309
1309
// initial state
1310
1310
expect ( field . formControl . $dirty ) . to . be . false
1311
1311
expect ( field . formControl . $touched ) . to . be . false
1312
-
1313
1312
// modification
1314
1313
scope . model . foo = '~=[,,_,,]:3'
1315
1314
field . formControl . $setTouched ( )
@@ -1427,6 +1426,43 @@ describe('formly-field', function() {
1427
1426
expect ( ( ) => field . resetModel ( ) ) . to . not . throw ( )
1428
1427
} )
1429
1428
1429
+ it ( 'should reset the form state on the input and form both' , ( ) => {
1430
+ const field = getNewField ( { key : 'foo' } )
1431
+ scope . fields = [ field ]
1432
+ compileAndDigest ( `
1433
+ <form name="theForm">
1434
+ <formly-form form="theForm" model="model" fields="fields" options="options"></formly-form>
1435
+ </form>
1436
+ ` )
1437
+ // initial state
1438
+ expect ( field . formControl . $dirty ) . to . be . false
1439
+ expect ( field . formControl . $touched ) . to . be . false
1440
+ expect ( scope . theForm . $dirty ) . to . be . false
1441
+ expect ( scope . theForm . $pristine ) . to . be . true
1442
+ // modification
1443
+ scope . model . foo = '~=[,,_,,]:3'
1444
+ field . formControl . $setTouched ( )
1445
+ field . formControl . $setDirty ( )
1446
+ scope . $digest ( )
1447
+
1448
+ // expect modification
1449
+ expect ( field . formControl . $dirty ) . to . be . true
1450
+ expect ( field . formControl . $touched ) . to . be . true
1451
+ expect ( scope . theForm . $dirty ) . to . be . true
1452
+ expect ( scope . theForm . $pristine ) . to . be . false
1453
+ expect ( field . formControl . $modelValue ) . to . eq ( '~=[,,_,,]:3' )
1454
+
1455
+ // reset state
1456
+ field . resetModel ( )
1457
+
1458
+ // expect reset
1459
+ expect ( field . formControl . $modelValue ) . to . be . empty
1460
+ expect ( field . formControl . $touched ) . to . be . false
1461
+ expect ( field . formControl . $dirty ) . to . be . false
1462
+ expect ( scope . theForm . $dirty ) . to . be . false
1463
+ expect ( scope . theForm . $pristine ) . to . be . true
1464
+ } )
1465
+
1430
1466
it ( `should not digest if there's a digest in progress` , ( ) => {
1431
1467
scope . fields = [ getNewField ( ) ]
1432
1468
compileAndDigest ( )
0 commit comments