diff --git a/specs/Formsy-spec.js b/specs/Formsy-spec.js
index ed007ef..108ce84 100755
--- a/specs/Formsy-spec.js
+++ b/specs/Formsy-spec.js
@@ -440,4 +440,49 @@ describe('Formsy', function () {
});
+ describe("value === false", function() {
+ var onSubmit;
+ var TestInput = React.createClass({
+ mixins: [Formsy.Mixin],
+ getDefaultProps: function() {
+ return {
+ type: "text",
+ };
+ },
+ changeValue: function() {
+ this.setValue(e.target[this.props.type === "checkbox" ? "checked" : "value"]);
+ },
+ render: function () {
+ return
+ }
+ });
+
+ var TestForm = React.createClass({
+ render: function () {
+ return (
+
+
+
+
+ );
+ }
+ });
+
+ beforeEach(function() {
+ onSubmit = jasmine.createSpy("onSubmit");
+ });
+
+ it("should call onSubmit correctly", function() {
+ var form = TestUtils.renderIntoDocument();
+ TestUtils.Simulate.submit(form.getDOMNode());
+ expect(onSubmit).toHaveBeenCalledWith({foo: false});
+ });
+
+ it("should allow dynamic changes to false", function() {
+ var form = TestUtils.renderIntoDocument();
+ form.setProps({value: false});
+ TestUtils.Simulate.submit(form.getDOMNode());
+ expect(onSubmit).toHaveBeenCalledWith({foo: false});
+ });
+ });
});
diff --git a/src/Mixin.js b/src/Mixin.js
index b436c72..48c8cd2 100644
--- a/src/Mixin.js
+++ b/src/Mixin.js
@@ -1,7 +1,7 @@
module.exports = {
getInitialState: function () {
return {
- _value: this.props.value ? this.props.value : '',
+ _value: this.props.value !== undefined ? this.props.value : '',
_isValid: true,
_isPristine: true
};
@@ -59,7 +59,7 @@ module.exports = {
// the value, set the value again running a validation
if (prevProps.validations !== this.props.validations || isValueChanged()) {
- this.setValue(this.props.value || '');
+ this.setValue(this.props.value === undefined ? '' : this.props.value);
}
},