import React, { Component } from 'react'; export default class Code extends Component { constructor(props) { super(props); this.state = { auth_code1: '', auth_code2: '', auth_code3: '', auth_code4: '', flag: false, } } flagSetter = () => { this.setState({ flag: true, }) } changeValue = (e) => { if (e.target.value.match("^[0-9]{1}$")) { this.setState({ [e.target.name]: e.target.value, }) if(e.target.name === 'auth_code1'){ this.setState({o1:e.target.value}) this.inputRef2.focus(); }else if(e.target.name === 'auth_code2'){ this.setState({o2:e.target.value}) this.inputRef3.focus(); }else if(e.target.name === 'auth_code3'){ this.setState({o3:e.target.value}) this.inputRef4.focus(); }else if(e.target.name === 'auth_code4'){ const o4 = e.target.value; const {o1,o2,o3} = this.state this.props.parent.setState({otp:`${o1}${o2}${o3}${o4}`}) return; } } else{ return; } } keyboardEvent = (e) => { if (e.keyCode === 8) { this.setState({ [e.target.name]: '', }); if(e.target.name === 'auth_code1'){ return; }else if(e.target.name === 'auth_code2'){ this.inputRef1.focus(); return; }else if(e.target.name === 'auth_code3'){ this.inputRef2.focus(); return; }else if(e.target.name === 'auth_code4'){ this.inputRef3.focus(); return; } } } componentDidMount() { this.inputRef1.focus(); } render() { return( <>
کد تایید رو برات فرستادم. اینجا واردش کن