Skip to content

Commit

Permalink
fix(Field): falsy values in contructor: fix alibaba-fusion#897
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkahn committed Jul 19, 2019
1 parent 530896d commit 3d1743d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
11 changes: 11 additions & 0 deletions test/field/options-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 3d1743d

Please sign in to comment.