question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trigger focus on ui-textbox?

See original GitHub issue

I have a ui-textbox inside a ui-confirm modal. I want the text input to be focused when the modal is shown, but using the autofocus directive doesn’t work.

I also tried adding a ref to the ui-textbox elemnt and call this.$refs.myInput.focus() but it didn’t do anything.

How can I manually focus the input, or make sure the input is focused when it is shown inside the modal?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
JosephusPayecommented, Mar 8, 2017

Hi @Cristy94,

This is something I’ve needed recently as well, and will be part of the next release as a focus() method on UiTextbox. For now, you can use this:

this.$refs.myInput.$refs.input.focus();
1reaction
kilobyte2007commented, Mar 30, 2020

@wbern for autofocusing on elements inside modals, this I created a directive in my project which call the focus() method on keen-ui textbox component (note that my modals are hidden with v-if):

Vue.directive('autofocus', {
  inserted (el, binding, vnode) {
    setTimeout(() => {
      vnode.componentInstance && vnode.componentInstance.focus()
    })
  }
})

…then use it like this:

<ui-textbox v-autofocus/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you automatically set the focus to a textbox when a ...
If you're using jquery: $(function() { $("#Box1").focus(); });. or prototype: Event.observe(window, 'load', function() { $("Box1").focus(); });.
Read more >
Set focus to input text box with JavaScript/jQuery | Techie Delight
With jQuery, you can use the .focus() method to trigger the “focus” JavaScript event on an element. This method is a shortcut for...
Read more >
HTMLElement.focus() - Web APIs | MDN
The HTMLElement.focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will ...
Read more >
.focus() | jQuery API Documentation
The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements,...
Read more >
JQuery | Set focus on a form input text field on page load
The task is to set the focus on form input text field using JQuery. To do so, Here are a few of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found