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

Commit 559fddb

Browse files
author
Kent C. Dodds
committed
Merge pull request #553 from bjspencer/master
fix(formly-field): Issue #510 Fixes formly-field to handle multiple inputs in a single form control
2 parents 46cfa65 + 4104128 commit 559fddb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/directives/formly-field.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,20 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
374374
function addShowMessagesWatcher() {
375375
stopWatchingShowError = scope.$watch(function watchShowValidationChange() {
376376
const customExpression = formlyConfig.extras.errorExistsAndShouldBeVisibleExpression
377-
const {options, fc} = scope
378-
if (!fc.$invalid) {
377+
const options = scope.options
378+
const formControls = arrayify(scope.fc)
379+
if (!formControls.some(fc => fc.$invalid)) {
379380
return false
380381
} else if (typeof options.validation.show === 'boolean') {
381382
return options.validation.show
382383
} else if (customExpression) {
383-
return formlyUtil.formlyEval(scope, customExpression, fc.$modelValue, fc.$viewValue)
384+
return formControls.some(fc =>
385+
formlyUtil.formlyEval(scope, customExpression, fc.$modelValue, fc.$viewValue))
384386
} else {
385-
const noTouchedButDirty = (angular.isUndefined(fc.$touched) && fc.$dirty)
386-
return (scope.fc.$touched || noTouchedButDirty)
387+
return formControls.some(fc => {
388+
const noTouchedButDirty = (angular.isUndefined(fc.$touched) && fc.$dirty)
389+
return (fc.$touched || noTouchedButDirty)
390+
})
387391
}
388392
}, function onShowValidationChange(show) {
389393
scope.options.validation.errorExistsAndShouldBeVisible = show

src/directives/formly-field.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ describe('formly-field', function() {
13661366
})
13671367

13681368
describe(`options.validation.errorExistsAndShouldBeVisible`, () => {
1369-
describe.skip(`multiple ng-model elements`, () => {
1369+
describe(`multiple ng-model elements`, () => {
13701370
beforeEach(() => {
13711371
scope.fields = [
13721372
{
@@ -1396,7 +1396,7 @@ describe('formly-field', function() {
13961396
compileAndDigest()
13971397

13981398
invalidateAndTouchFields()
1399-
expect(spy).to.have.been.calledWith(sinon.match.array, sinon.match.array)
1399+
expect(spy).to.have.been.calledTwice // once for each form control.
14001400
})
14011401

14021402
function invalidateAndTouchFields() {

0 commit comments

Comments
 (0)