From aae7af6895c2fb893e669bc741158f3c1721d3b8 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Tue, 15 Nov 2016 17:58:11 +0100 Subject: [PATCH] Adds onPaste event to Inputs #3127 --- js/src/modals/AddContract/addContract.js | 1 + js/src/ui/Form/Input/input.js | 28 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/js/src/modals/AddContract/addContract.js b/js/src/modals/AddContract/addContract.js index 57773d2dc..4c73d3da0 100644 --- a/js/src/modals/AddContract/addContract.js +++ b/js/src/modals/AddContract/addContract.js @@ -227,6 +227,7 @@ export default class AddContract extends Component { onEditAbi = (abiIn) => { const { api } = this.context; const { abi, abiError, abiParsed } = validateAbi(abiIn, api); + this.setState({ abi, abiError, abiParsed }); } diff --git a/js/src/ui/Form/Input/input.js b/js/src/ui/Form/Input/input.js index e99b4ae6b..47d0dde90 100644 --- a/js/src/ui/Form/Input/input.js +++ b/js/src/ui/Form/Input/input.js @@ -16,6 +16,7 @@ import React, { Component, PropTypes } from 'react'; import { TextField } from 'material-ui'; +import { noop } from 'lodash'; import CopyToClipboard from '../../CopyToClipboard'; @@ -81,7 +82,7 @@ export default class Input extends Component { } componentWillReceiveProps (newProps) { - if (newProps.value !== this.props.value) { + if ((newProps.value !== this.props.value) && (newProps.value !== this.state.value)) { this.setValue(newProps.value); } } @@ -131,6 +132,7 @@ export default class Input extends Component { onBlur={ this.onBlur } onChange={ this.onChange } onKeyDown={ this.onKeyDown } + onPaste={ this.onPaste } inputStyle={ inputStyle } min={ min } max={ max } @@ -180,9 +182,9 @@ export default class Input extends Component { } onChange = (event, value) => { - this.setValue(value); - - this.props.onChange && this.props.onChange(event, value); + this.setValue(value, () => { + this.props.onChange && this.props.onChange(event, value); + }); } onBlur = (event) => { @@ -196,6 +198,14 @@ export default class Input extends Component { this.props.onBlur && this.props.onBlur(event); } + onPaste = (event) => { + const value = event.clipboardData.getData('Text'); + + window.setTimeout(() => { + this.onSubmit(value); + }, 0); + } + onKeyDown = (event) => { const { value } = event.target; @@ -209,12 +219,12 @@ export default class Input extends Component { } onSubmit = (value) => { - this.setValue(value); - - this.props.onSubmit && this.props.onSubmit(value); + this.setValue(value, () => { + this.props.onSubmit && this.props.onSubmit(value); + }); } - setValue (value) { - this.setState({ value }); + setValue (value, cb = noop) { + this.setState({ value }, cb); } }