@@ -1015,7 +1015,7 @@ describe('formly-field', function() {
1015
1015
expect ( ctrl . $viewValue ) . to . equal ( 'hello! boo!' ) ;
1016
1016
} ) ;
1017
1017
1018
- it ( `should format a model value right from the start and the form should still be pristine` , ( ) => {
1018
+ it ( `should format a model value right from the start and the controller should still be pristine` , ( ) => {
1019
1019
scope . model = { myKey : 'hello' } ;
1020
1020
scope . fields = [ getNewField ( {
1021
1021
key : 'myKey' ,
@@ -1030,6 +1030,37 @@ describe('formly-field', function() {
1030
1030
expect ( ctrl . $pristine ) . to . equal ( true ) ;
1031
1031
} ) ;
1032
1032
1033
+ it ( `should format a model value on initilization and keep the form state dirty if it was already dirty` , ( ) => {
1034
+ scope . model = { myKey : 'hello' } ;
1035
+ scope . fields = [ getNewField ( {
1036
+ key : 'myKey' ,
1037
+ formatters : [ '"!" + $viewValue + "!"' ]
1038
+ } ) ] ;
1039
+ compileAndDigest ( ) ;
1040
+ scope . theForm . $setDirty ( ) ;
1041
+
1042
+ const ctrl = getNgModelCtrl ( ) ;
1043
+
1044
+ expect ( ctrl . $viewValue ) . to . equal ( '!hello!' ) ;
1045
+ expect ( scope . theForm . $dirty ) . to . equal ( true ) ;
1046
+
1047
+ } ) ;
1048
+
1049
+ it ( `should format a model value on initilization and keep the form state pristine if it was already pristine` , ( ) => {
1050
+ scope . model = { myKey : 'hello' } ;
1051
+ scope . fields = [ getNewField ( {
1052
+ key : 'myKey' ,
1053
+ formatters : [ '"!" + $viewValue + "!"' ]
1054
+ } ) ] ;
1055
+ compileAndDigest ( ) ;
1056
+
1057
+ const ctrl = getNgModelCtrl ( ) ;
1058
+
1059
+ expect ( ctrl . $viewValue ) . to . equal ( '!hello!' ) ;
1060
+ expect ( scope . theForm . $pristine ) . to . equal ( true ) ;
1061
+
1062
+ } ) ;
1063
+
1033
1064
it . skip ( `should handle multiple form controllers when formatting a model value right from the start` , ( ) => {
1034
1065
scope . model = {
1035
1066
multiNgModel : {
0 commit comments