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

Commit 10ee65f

Browse files
committed
Bug #423 - Implementing additional logic to get formatters to format the initial model value
1 parent 3ff6ead commit 10ee65f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/directives/formly-field.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,16 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
359359

360360
function addFormatters() {
361361
setParsersOrFormatters('formatters');
362+
const ctrl = scope.fc;
363+
if (ctrl.$formatters) {
364+
let value = ctrl.$modelValue;
365+
ctrl.$formatters.forEach((formatter) => {
366+
value = formatter(value);
367+
});
368+
369+
ctrl.$setViewValue(value);
370+
ctrl.$render();
371+
}
362372
}
363373

364374
function setParsersOrFormatters(which) {

src/directives/formly-field.test.js

Lines changed: 1 addition & 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.skip(`should format a model value right from the start`, () => {
1018+
it(`should format a model value right from the start`, () => {
10191019
scope.model = {myKey: 'hello'};
10201020
scope.fields = [getNewField({
10211021
key: 'myKey',

0 commit comments

Comments
 (0)