soywod / react-pin-field

📟 React component for entering PIN codes.
https://soywod.github.io/react-pin-field/
MIT License
413 stars 24 forks source link

OnComplete not being fired #17

Closed byeze closed 4 years ago

byeze commented 4 years ago

When I complete the Pin Field Group, the function that is coded to fire when the pin is completed is not being called.

Example Code:

handlePinCode() {
    alert('Code completed')
    this.setState({ isLoading: true });

    setTimeout(() => this.setState({ isLoading: false }), 1000);
}

render() {
    return (
        <div className="text-center m-5">
            <h2>Bienvenido</h2>

            <PinField
                length="4"
                validate={/^[0-9]$/}
                onComplete={this.handlePinCode}
                disabled={this.state.isLoading}
                type="number"
            ></PinField>
        </div>
    );
}
soywod commented 4 years ago

It's because length should be a number, not a string. It works as expected with a number: https://codesandbox.io/s/hungry-nobel-gnp3u. Which code editor do you use? It should have warned you, strange.

byeze commented 4 years ago

I'm using Vscode. Thank you!