Skip to content

Commit

Permalink
fix(Field): falsy defaultValue prop: fix #897
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkahn committed Jul 19, 2019
1 parent 016c13e commit 530896d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Field {
let defaultValue;
if (typeof initValue !== 'undefined') {
defaultValue = initValue;
} else if (originalProps[defaultValueName]) {
} else if (typeof originalProps[defaultValueName] !== 'undefined') {
defaultValue = originalProps[defaultValueName];
} else if (parseName) {
defaultValue = getIn(this.values, name);
Expand Down
23 changes: 23 additions & 0 deletions test/field/options-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ describe('options', () => {
done();
});

describe('defaultValue', () => {
it('should support `defaultValue`', function() {
const inputValue = 'my value';
const field = new Field(this);
field.init('input', {props: {defaultValue: inputValue}});
assert.equal(field.getValue('input'), inputValue);
});

it('should support `defaultValue` with different value name and make camel case', function() {
const inputValue = 'my value';
const field = new Field(this);
field.init('input', { valueName: 'myValue', props: { defaultMyValue: inputValue} });
assert.equal(field.getValue('input'), inputValue);
});

it('should support `defaultValue` with falsy value', function() {
const inputValue = 0;
const field = new Field(this);
field.init('input', {props: {defaultValue: inputValue}});
assert.equal(field.getValue('input'), inputValue);
});
})

describe('values', () => {
it('should set default field input values when given `values` in constructor', function() {
const inputValue = 'my value';
Expand Down

0 comments on commit 530896d

Please sign in to comment.