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

Crashing browser #395

Closed
PINHOf opened this issue Oct 5, 2015 · 5 comments
Closed

Crashing browser #395

PINHOf opened this issue Oct 5, 2015 · 5 comments
Labels

Comments

@PINHOf
Copy link

PINHOf commented Oct 5, 2015

Hello,

I have a form where I have multiple inputs, so the accept button cannot close my keyboard. The form is shown on a modal.

I prepared this https://jsfiddle.net/3cfyjhgw/3/ so you can see the problem. Try the following:

  1. Insert several numbers
  2. Click the button accept
  3. Click the button clear
  4. Enter again several numbers
  5. Click various times in accept
  6. Try to enter numbers again

Well done, you've now crashed the browser tab. I have tried on Chrome and Firefox and both have the problem.

At first I thought the problem might be due to the accepted event I was firing and also thought it was my code problem, but after a few tests I finally realize that the plugin was causing the issue.

Thanks.

EDIT 1: I tested again and actually it seems that it only needs to click several times on accept button to crash it..

@Mottie
Copy link
Owner

Mottie commented Oct 6, 2015

Hi @PINHOf!

Thanks for reporting this. It looks like an issue with the alwaysOpen code. I've been trying to work out a fix, but it isn't cooperating. I hope to have this solved soon.

@Mottie Mottie added the Bug label Oct 6, 2015
@PINHOf
Copy link
Author

PINHOf commented Oct 6, 2015

Hey @Mottie,

I have run a few tests and find out that the problem is on this line:

base.$el.bind(o.openOn + base.namespace, function(){ base.focusOn(); });

Which is inside the base.close function.

Switching to:

base.el.bind(o.openOn + base.namespace, function(){ base.focusOn(); });

Removes the issue, but I dunno why you were using base.$el and not base.el.
You can try it with the change at https://jsfiddle.net/3cfyjhgw/4/

EDIT 1: Wrong JSFiddle link, this one is OK: https://jsfiddle.net/3cfyjhgw/5/

@Mottie
Copy link
Owner

Mottie commented Oct 6, 2015

base.$el is the the jQuery object of the input while base.el is the DOM element. Using base.el.bind is likely not doing anything... I did try skipping that bind, but the issue was trying to use the keyboard a second, or third time after using the accept key.

I know the problem is that the focusOn function is called in an infinite loop, I just had other distractions that I didn't get to finish working on a fix. I'll try again today.

@PINHOf
Copy link
Author

PINHOf commented Oct 6, 2015

You're right. The problem is on the function focusOn. After digging more of your code I found out that you have, from what I have understand, an "!" exclamation point where you don't need it.

Inside the $keyboard.caret function:

var start, end, txt, pos,
noFocus = $el.getkeyboard() && $el.getkeyboard().options.noFocus;

if (!noFocus) { $el.focus(); }

The variable noFocus returns false, which means that when it's false you want to focus the jQuery object. But in your code you are saying "when it's not false, focus", and "not false" means it's true, therefore you are constantly focusing the element causing it to crash.

The solution is just to remove the "!"
if (noFocus) { $el.focus(); }

Check this JSFiddle https://jsfiddle.net/3cfyjhgw/6/ and open the console to inspect.

Correct me if I'm wrong, but it seems right.

@Mottie Mottie closed this as completed in a56b973 Nov 15, 2015
@Mottie
Copy link
Owner

Mottie commented Nov 15, 2015

Actually, noFocus is an option set by the developer. It means you want to interact with the input without giving it focus.

I ended up not using the .focusOn function when a keyboard is set to alwaysOpen.

Try out this updated demo.... note that when autoAccept is false, like it is in this demo, when you hover over the other keyboard, the input reverts to it's original value (since it was last accepted).

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

No branches or pull requests

2 participants