Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit ab810f3

Browse files
committed
Fixes bug #432. I think it is a fundamental problem that AngularJS doesn't run the formatters unless the $modelValue changes. Meaning that on initialization Angular won't run the formatters. There are some issues open to change how angular handles formatters including a PR (angular/angular.js#10764). Currently I don't see a way to run the formatters without causing a SetDirty event from triggering. The only solution I see is to reset the field controller to pristine after running the formatter the first time.
If someone has a different workaround to this Angular concept I'd love to explore a different solution. -🐙
1 parent 774531c commit ab810f3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/directives/formly-field.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
368368

369369
ctrl.$setViewValue(value);
370370
ctrl.$render();
371+
ctrl.$setPristine();
371372
}
372373
}
373374

src/directives/formly-field.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ describe('formly-field', function() {
10151015
expect(ctrl.$viewValue).to.equal('hello! boo!');
10161016
});
10171017

1018-
it(`should format a model value right from the start`, () => {
1018+
it(`should format a model value right from the start and the form should still be pristine`, () => {
10191019
scope.model = {myKey: 'hello'};
10201020
scope.fields = [getNewField({
10211021
key: 'myKey',
@@ -1026,6 +1026,8 @@ describe('formly-field', function() {
10261026
const ctrl = getNgModelCtrl();
10271027

10281028
expect(ctrl.$viewValue).to.equal('!hello!');
1029+
expect(ctrl.$dirty).to.equal(false);
1030+
expect(ctrl.$pristine).to.equal(true);
10291031
});
10301032

10311033
it.skip(`should handle multiple form controllers when formatting a model value right from the start`, () => {

0 commit comments

Comments
 (0)