Added touched option for inputs

pull/200/head
Vladimir Volek 6 years ago
parent 9437cb25e8
commit 93000adf9e

@ -50,7 +50,8 @@ type State = {
signMessage: string,
verifyAddress: string,
verifyMessage: string,
verifySignature: string
verifySignature: string,
touched: Array<string>
}
class SignVerify extends Component<Props, State> {
@ -61,10 +62,22 @@ class SignVerify extends Component<Props, State> {
verifyAddress: '',
verifyMessage: '',
verifySignature: '',
touched: [],
};
}
setTouchedInput = (inputName: string) => {
if (!this.state.touched.includes(inputName)) {
this.setState(prevState => ({
touched: [...prevState.touched, inputName],
}));
}
}
shouldValidate = (inputName: string) => this.state.touched.includes(inputName)
handleInputChange = (event: SyntheticInputEvent<Text>) => {
this.setTouchedInput(event.target.name);
this.setState({ [event.target.name]: event.target.value });
}
@ -155,8 +168,8 @@ class SignVerify extends Component<Props, State> {
value={this.state.verifyAddress}
onChange={this.handleInputChange}
type="text"
state={(this.state.verifyAddress && validateAddress(this.state.verifyAddress)) ? 'error' : null}
bottomText={this.state.verifyAddress !== '' ? validateAddress(this.state.verifyAddress) : null}
state={(this.shouldValidate('verifyAddress') && validateAddress(this.state.verifyAddress)) ? 'error' : null}
bottomText={this.shouldValidate('verifyAddress') ? validateAddress(this.state.verifyAddress) : null}
isSmallText
/>
</Row>

Loading…
Cancel
Save