Skip to content

Commit

Permalink
Merge pull request #29731 from saranshbalyan-1234/stop-magiccode-inst…
Browse files Browse the repository at this point in the history
…ant-submit-onchange

auto submit magic code during first submit only
  • Loading branch information
Joel Bettner authored Oct 17, 2023
2 parents fe2b2ce + 3651dfd commit 8917f95
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function MagicCodeInput(props) {
const [input, setInput] = useState('');
const [focusedIndex, setFocusedIndex] = useState(0);
const [editIndex, setEditIndex] = useState(0);
const [wasSubmitted, setWasSubmitted] = useState(false);

const blurMagicCodeInput = () => {
inputRefs.current[editIndex].blur();
Expand All @@ -124,9 +125,12 @@ function MagicCodeInput(props) {

const validateAndSubmit = () => {
const numbers = decomposeString(props.value, props.maxLength);
if (!props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) {
if (wasSubmitted || !props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) {
return;
}
if (!wasSubmitted) {
setWasSubmitted(true);
}
// Blurs the input and removes focus from the last input and, if it should submit
// on complete, it will call the onFulfill callback.
blurMagicCodeInput();
Expand Down

0 comments on commit 8917f95

Please sign in to comment.