Copy Paste issue.
Closed this issue · 2 comments
Hi,
I've included this package in my project. In that, is a requirement that when the user copies and pastes the OTP, it should fill the whole fields.
At the moment it only fills till the field in which the user pasted data.
for example, if the user tries to paste in the 3rd input box and the total length is 6, it will start from 0 to 3rd position. I forked the code and checked. There is a code to paste data from focused input onwards at line number 246.
Old code
const otp = this.getOtpValue();
let nextActiveInput = activeInput;
// Get pastedData in an array of max size (num of inputs - current position)
const pastedData = e.clipboardData
.getData('text/plain')
.slice(0, numInputs - activeInput)
.split('');
// Paste data from focused input onwards
for (let pos = 0; pos < numInputs; ++pos) {
if (pos >= activeInput && pastedData.length > 0) {
otp[pos] = pastedData.shift();
nextActiveInput++;
}
}
The code I modified.
const otp = this.getOtpValue();
let nextActiveInput = 0;
// Get pastedData in an array of max size (num of inputs - current position)
const pastedData = e.clipboardData
.getData('text/plain')
.slice(0, numInputs - 0)
.split('');
// Paste data from focused input onwards
for (let pos = 0; pos < numInputs; ++pos) {
if (pos >= 0 && pastedData.length > 0) {
otp[pos] = pastedData.shift();
nextActiveInput++;
}
}
I know this will be a case for a small audience, How can I use this in my app?
Any help would be appreciated.
@rahulje9 if you would like to modify just these lines in your code, you can use https://github.com/ds300/patch-package. I'm not sure if it should paste always the whole code. I would change it if pasted code length is equal to the number of inputs. I've handled it as described here in the new version.
Hi @rahulje9 Could you please tell me in which file you have altered the changes.
@dsznajder have you added this feature on the latest version?
Because i was also facing this issue in android but on ios it is working fine.