From 559edac928ef12c527575bdfdca689c9d00c788e Mon Sep 17 00:00:00 2001 From: Hoang Nhat Nguyen Date: Thu, 20 Oct 2016 14:56:42 +0700 Subject: [PATCH 1/3] Fix eslint error --- src/FormsyText.jsx | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/FormsyText.jsx b/src/FormsyText.jsx index f1644b5..aaab3f5 100644 --- a/src/FormsyText.jsx +++ b/src/FormsyText.jsx @@ -12,10 +12,10 @@ const FormsyText = React.createClass({ onBlur: React.PropTypes.func, onChange: React.PropTypes.func, onKeyDown: React.PropTypes.func, + updateImmediately: React.PropTypes.bool, validationError: React.PropTypes.string, validationErrors: React.PropTypes.object, validations: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.object]), - updateImmediately: React.PropTypes.bool, value: React.PropTypes.any, }, @@ -55,14 +55,6 @@ const FormsyText = React.createClass({ return props.value || props.defaultValue || ''; }, - // Controlled component - componentWillReceiveProps(nextProps) { - if (nextProps.value !== this.props.value) - this.setState({ - value: nextProps.value - }); - }, - handleBlur: function handleBlur(event) { this.setValue(event.currentTarget.value); delete this.changeValue; @@ -96,9 +88,7 @@ const FormsyText = React.createClass({ this.props.onChange(event, event.currentTarget.value); // Uncontrolled component } else { - this.setState({ - value: event.currentTarget.value - }); + this.setState({ value: event.currentTarget.value }); } }, @@ -115,9 +105,8 @@ const FormsyText = React.createClass({ validations, // eslint-disable-line no-unused-vars validationError, // eslint-disable-line no-unused-vars validationErrors, // eslint-disable-line no-unused-vars - onFocus, value, // eslint-disable-line no-unused-vars - ...rest + ...rest, } = this.props; return ( @@ -131,7 +120,7 @@ const FormsyText = React.createClass({ value={this.state.value} /> ); - } + }, }); export default FormsyText; From d77542aaf5bc69fed99a0776f36e12721dc05f9a Mon Sep 17 00:00:00 2001 From: Hoang Nhat Nguyen Date: Thu, 20 Oct 2016 15:03:51 +0700 Subject: [PATCH 2/3] Fix value cannot change when user passes onChange prop --- src/FormsyText.jsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/FormsyText.jsx b/src/FormsyText.jsx index aaab3f5..0de03fc 100644 --- a/src/FormsyText.jsx +++ b/src/FormsyText.jsx @@ -83,12 +83,11 @@ const FormsyText = React.createClass({ } } + this.setState({ value: event.currentTarget.value }); + // Controlled component if (this.props.onChange) { this.props.onChange(event, event.currentTarget.value); - // Uncontrolled component - } else { - this.setState({ value: event.currentTarget.value }); } }, From d641703f33405a000f33c51dfb4ac355beb8194f Mon Sep 17 00:00:00 2001 From: Hoang Nhat Nguyen Date: Thu, 20 Oct 2016 16:30:46 +0700 Subject: [PATCH 3/3] Remove invalid props of input tag --- src/FormsyText.jsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/FormsyText.jsx b/src/FormsyText.jsx index 0de03fc..29fd374 100644 --- a/src/FormsyText.jsx +++ b/src/FormsyText.jsx @@ -83,12 +83,9 @@ const FormsyText = React.createClass({ } } - this.setState({ value: event.currentTarget.value }); - // Controlled component - if (this.props.onChange) { - this.props.onChange(event, event.currentTarget.value); - } + this.setState({ value: event.currentTarget.value }); + if (this.props.onChange) this.props.onChange(event, event.currentTarget.value); }, handleKeyDown: function handleKeyDown(event) { @@ -101,6 +98,7 @@ const FormsyText = React.createClass({ render() { const { defaultValue, // eslint-disable-line no-unused-vars + updateImmediately, // eslint-disable-line no-unused-vars validations, // eslint-disable-line no-unused-vars validationError, // eslint-disable-line no-unused-vars validationErrors, // eslint-disable-line no-unused-vars