From 3d1743db3255191dc5a9f6fa0a0acdac23846685 Mon Sep 17 00:00:00 2001 From: Justin Kahn Date: Fri, 19 Jul 2019 18:36:03 +0800 Subject: [PATCH] fix(Field): falsy values in contructor: fix #897 --- src/field/index.js | 4 ++-- test/field/options-spec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/field/index.js b/src/field/index.js index d5fdb0659b..ec68c2d90d 100644 --- a/src/field/index.js +++ b/src/field/index.js @@ -107,8 +107,8 @@ class Field { defaultValue = originalProps[defaultValueName]; } else if (parseName) { defaultValue = getIn(this.values, name); - } else { - defaultValue = (this.values && this.values[name]) || undefined; + } else if (this.values && typeof this.values[name] !== 'undefined') { + defaultValue = this.values[name]; } Object.assign(field, { diff --git a/test/field/options-spec.js b/test/field/options-spec.js index dbb19dccdc..4e25ed2762 100644 --- a/test/field/options-spec.js +++ b/test/field/options-spec.js @@ -197,6 +197,17 @@ describe('options', () => { assert.equal(field.getValue('input'), inputValue); }); + it('should set default field input values when given falsy `values` in constructor', function() { + const inputValue = 0; + const field = new Field(this, { + values: { + input: inputValue + }, + }); + field.init('input'); + assert.equal(field.getValue('input'), inputValue); + }); + it('should set default field input values when given `values` and `parseName` = true in constructor', function() { const inputValue = 'my value'; const field = new Field(this, {