diff --git a/src/dom/components/ReactDOMInput.js b/src/dom/components/ReactDOMInput.js index 2d552fc923..e6ba3ed3df 100644 --- a/src/dom/components/ReactDOMInput.js +++ b/src/dom/components/ReactDOMInput.js @@ -62,7 +62,8 @@ var ReactDOMInput = ReactCompositeComponent.createClass({ }, getValue: function() { - return this.props.value != null ? this.props.value : this.state.value; + // Cast `this.props.value` to a string so equality checks pass. + return this.props.value != null ? '' + this.props.value : this.state.value; }, render: function() { @@ -85,10 +86,12 @@ var ReactDOMInput = ReactCompositeComponent.createClass({ ); } if (this.props.value != null) { + // Cast `this.props.value` to a string so falsey values that cast to + // truthy strings are not ignored. DOMPropertyOperations.setValueForProperty( rootNode, 'value', - this.props.value || '' + '' + this.props.value || '' ); } }, diff --git a/src/eventPlugins/ChangeEventPlugin.js b/src/eventPlugins/ChangeEventPlugin.js index 6bb13d5e0e..835651fecd 100644 --- a/src/eventPlugins/ChangeEventPlugin.js +++ b/src/eventPlugins/ChangeEventPlugin.js @@ -169,7 +169,8 @@ var newValueProp = { return activeElementValueProp.get.call(this); }, set: function(val) { - activeElementValue = val; + // Cast to a string so we can do equality checks. + activeElementValue = '' + val; activeElementValueProp.set.call(this, val); } }; @@ -231,7 +232,7 @@ function handlePropertyChange(nativeEvent) { /** * If a `change` event should be fired, returns the target's ID. */ -function getTargetIDForInputEvent( +function getTargetIDForInputEvent( topLevelType, topLevelTarget, topLevelTargetID) {