diff --git a/src/field/index.js b/src/field/index.js index 0ec1831cf8..d5fdb0659b 100644 --- a/src/field/index.js +++ b/src/field/index.js @@ -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); diff --git a/test/field/options-spec.js b/test/field/options-spec.js index 47d7ea271e..dbb19dccdc 100644 --- a/test/field/options-spec.js +++ b/test/field/options-spec.js @@ -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';