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

Commit b38c1b2

Browse files
author
MCKRUZ
committed
fix(formly-field): Breaking change in @7.3.2? Key value? #566
Fixed this to handle GUIDS
1 parent 1db33a9 commit b38c1b2

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/directives/formly-field.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
8383
}
8484

8585
function shouldNotUseParseKey(key) {
86-
return angular.isNumber(key) || (/^\d/.test(key) && key.indexOf('[') === -1)
86+
return angular.isNumber(key) || !formlyUtil.containsSelector(key)
8787
}
8888

8989
function parseSet(key, model, newVal) {

src/directives/formly-field.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,30 @@ describe('formly-field', function() {
572572
expect(scope.model[key]).to.eq(defaultValue)
573573
})
574574

575+
it('should work with dashes in the key', () => {
576+
const key = 'address-1st-line'
577+
const defaultValue = 'baz'
578+
scope.fields = [
579+
{template: input, key, defaultValue},
580+
]
581+
scope.model = {}
582+
583+
compileAndDigest()
584+
expect(scope.model[key]).to.eq(defaultValue)
585+
})
586+
587+
it('should work with dashes and numerics in the key', () => {
588+
const key = 'b141c66a-2857-4196-847b-b2096fa6170d'
589+
const defaultValue = 'baz'
590+
scope.fields = [
591+
{template: input, key, defaultValue},
592+
]
593+
scope.model = {}
594+
595+
compileAndDigest()
596+
expect(scope.model[key]).to.eq(defaultValue)
597+
})
598+
575599
it('should work with nested keys with numbers in the key', () => {
576600
const key = 'foo3bar.baz4foobar'
577601
const defaultValue = 'baz'
@@ -581,7 +605,7 @@ describe('formly-field', function() {
581605
scope.model = {}
582606

583607
compileAndDigest()
584-
expect(scope.model.foo3bar.baz4foobar).to.equal(defaultValue)
608+
expect(scope.model.foo3bar.baz4foobar).to.eq(defaultValue)
585609
})
586610
})
587611

src/other/utils.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import angular from 'angular-fix'
22

33
export default {
4-
formlyEval, getFieldId, reverseDeepMerge, findByNodeName, arrayify, extendFunction, extendArray, startsWith, contains,
4+
containsSelector, containsSpecialChar, formlyEval, getFieldId, reverseDeepMerge, findByNodeName,
5+
arrayify, extendFunction, extendArray, startsWith, contains,
56
}
67

8+
function containsSelector(string) {
9+
return containsSpecialChar(string, '.') || (containsSpecialChar(string, '[') && containsSpecialChar(string, ']'))
10+
}
11+
12+
function containsSpecialChar(a, b) {
13+
if (!a || !a.indexOf) {
14+
return false
15+
}
16+
return a.indexOf(b) !== -1
17+
}
18+
19+
720
function formlyEval(scope, expression, $modelValue, $viewValue, extraLocals) {
821
if (angular.isFunction(expression)) {
922
return expression($viewValue, $modelValue, scope, extraLocals)

0 commit comments

Comments
 (0)