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

Commit 72453ec

Browse files
committedMar 18, 2016
fix(formly-field): fixed check in parseSet/parseGet to permit 0 keys
#658
1 parent 9532845 commit 72453ec

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎src/directives/formly-field.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
104104

105105
function parseSet(key, model, newVal) {
106106
// If either of these are null/undefined then just return undefined
107-
if (!key || !model) {
107+
if ((!key && key !== 0) || !model) {
108108
return
109109
}
110110
// If we are working with a number then $parse wont work, default back to the old way for now
@@ -121,7 +121,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
121121

122122
function parseGet(key, model) {
123123
// If either of these are null/undefined then just return undefined
124-
if (!key || !model) {
124+
if ((!key && key !== 0) || !model) {
125125
return undefined
126126
}
127127

‎src/directives/formly-field.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,13 @@ describe('formly-field', function() {
500500
expect(scope.fields[0].initialValue).to.eq(defaultValue)
501501
})
502502

503+
it(`should be set if the key is 0`, () => {
504+
scope.fields[0].key = 0
505+
compileAndDigest()
506+
507+
expect(scope.fields[0].initialValue).to.eq(defaultValue)
508+
})
509+
503510
describe(`nested keys`, () => {
504511
const nestedObject = 'foo.bar'
505512
const nestedArray = 'baz[0]'
@@ -546,6 +553,19 @@ describe('formly-field', function() {
546553
expect(scope.model[key]).to.eq(defaultValue)
547554
})
548555

556+
it('should get and set values when key is 0', () => {
557+
const key = 0
558+
const defaultValue = 'bar'
559+
560+
scope.fields = [
561+
{template: input, key, defaultValue},
562+
]
563+
scope.model = {}
564+
565+
compileAndDigest()
566+
expect(scope.model[key]).to.eq(defaultValue)
567+
})
568+
549569
it('should get and set values when key is alpha numeric with alpha first', () => {
550570
const key = 'A1'
551571
const defaultValue = 'bar'

0 commit comments

Comments
 (0)