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

call insertText but cursor is at begining #506

Closed
yangyili opened this issue Jan 5, 2017 · 5 comments
Closed

call insertText but cursor is at begining #506

yangyili opened this issue Jan 5, 2017 · 5 comments

Comments

@yangyili
Copy link

yangyili commented Jan 5, 2017

Hi:
when I call keyboard.reveal().insertText('hello'), keyboard openen with cursir at the beging
I saw the source code find a timer was excuted after insert text。the timer change the cursor position

I found the timer is:

base.timer2 = setTimeout(function () {
var undef;
base.opening = false;
// Number inputs don't support selectionStart and selectionEnd
// Number/email inputs don't support selectionStart and selectionEnd
if (!/(number|email)/i.test(base.el.type) && !o.caretToEnd) {
// caret position is always 0,0 in webkit; and nothing is focused at this point... odd
// save caret position in the input to transfer it to the preview
// inside delay to get correct caret position
base.saveCaret(undef, undef, base.$el);
}
if (o.initialFocus) {
$keyboard.caret(base.$preview, base.last);
}
// save event time for keyboards with stayOpen: true
base.last.eventTime = new Date().getTime();
base.$el.trigger($keyboard.events.kbVisible, [base, base.el]);
base.timer = setTimeout(function () {
// get updated caret information after visible event - fixes #331
if (base) { // Check if base exists, this is a case when destroy is called, before timers fire
base.saveCaret();
}
}, 200);
}, 10);

@Mottie
Copy link
Owner

Mottie commented Jan 5, 2017

Hi @yangyili!

Setting the initialFocus option to false should prevent that behavior.

@yangyili
Copy link
Author

yangyili commented Jan 5, 2017

Thank you @Mottie very much
the initialFocus option works, but it cause another problem that inserttext will not trigger keyboardChange event
I have to manul trigger keyboardChange
I will try another method or option
thanks again

@Mottie
Copy link
Owner

Mottie commented Jan 5, 2017

Hmm, maybe you can do this instead:

keyboard = $("#keyboard").data("keyboard");
keyboard.reveal().insertText('hello');
keyboard.$el.trigger('change');

I don't want to trigger a change inside the insertText function since at this point it has not passed through the other checks like checking for combos or max length.

What if I make the insertText function return the keyboard object so you can chain it?

keyboard = $("#keyboard").data("keyboard");
keyboard.reveal().insertText('hello').$el.trigger("change");

@yangyili
Copy link
Author

yangyili commented Jan 5, 2017

ok thank you very much
I use keyboardChange instead of change for keydown or keyup event

@Mottie
Copy link
Owner

Mottie commented Jan 5, 2017

Oops, I had to make a change in the code above. The el.trigger() should have been $el.trigger()... keyboard.el points to the DOM element while keyboard.$el points to the jQuery element of the input.

Anyway, I just released v1.26.8... the following functions are now chainable:

  • checkMaxLength
  • insertText
  • redraw - new parameter - docs
  • showKeySet
  • toggle
  • caret - new function - docs

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

No branches or pull requests

2 participants