Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasting does not trigger complete event #2

Open
bartekadams opened this issue Mar 2, 2020 · 2 comments
Open

Pasting does not trigger complete event #2

bartekadams opened this issue Mar 2, 2020 · 2 comments

Comments

@bartekadams
Copy link

After pasting code, that has required length the complete event is not triggered.
Console shows error like:
Uncaught TypeError: Cannot read property 'removeAttribute' of null

I managed to change part of paste event, which fixes that error (You should not focus field further than last):

if (i < pasted.length - 1) {
  that.focus(i+1);
} else {
  pasteField.blur();
}

But also after that complete event is not triggered.
I read that it is run only on input event in your code. I wonder if it relates to browsers triggering or not input event on paste? I had to also manually dispatch event on each input field in paste event to make it work.

pasteField.dispatchEvent(new Event('input'));

Btw it is possible to paste more digits than one in fields other than first.

I know this is a lot, but can you look into that?

System configuration

Browser: Chrome 80.0.3987.106 (Mac)

@TheNetStriker
Copy link

I'm also having this problem. I solved it like this:

for (var i = 0; i < that.settings.fields; i++){
					
	var pasteField = that.getField(i);
	
	pasteField.removeAttribute('readonly');
	pasteField.value = pasted[i];
	that.values[i] = pasted[i];
	
	if (!that.validateInput(i))
		break;
	
	if (i < pasted.length - 1) {
		that.focus(i + 1);
	} else {
		if (that.settings.hideinput)
			this.value = that.settings.placeholder;

		var pin = that.values.join('');

		// reset the plugin
		if (that.settings.reset)
			that.reset();

		// fire complete callback
		that.settings.complete(pin);
	}
}

@zishanj
Copy link

zishanj commented Jun 12, 2021

replace:

that.focus(i+1);
with

if ( i+1 < that.settings.fields ) {
 that.focus( i + 1 );
} else {
 that.settings.complete( pasted );
}

It will fix 2 issues... one that will throw error due to i+1 exceeding the number of fields and another triggering complete event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants