Pregunta

I have a bunch of textareas and selectboxes in my view. All these have proper tab indexes for keyboard navigation.
What is happening is that on load of this view, the last of the textareas is getting focus from somewhere and the view scrolls to that. Im not able to detect where is it getting focus from.

I tried putting an event handler for 'focus' on the textarea, and for 'scroll' on the container, but was not able to detect the origin of the event in Chrome Dev Tools. Is there any way i can detect where the focus on the textarea is coming from?

¿Fue útil?

Solución

There are two possible ways to set the focus:

  1. With an autofocus property. (see http://davidwalsh.name/autofocus)
  2. With javascript/jQuery

If the focus is set using autofocus simply remove that attribute.

If it's set by javascript/jQuery you can try to set an "Event Listener Breakpoint" in the Webkit DevTools.

Go to the 'Sources" tab and on the right/bottom under "Event Listener Breakpoint" select Control -> focus. This should pause the execution and show you where the focus is being set.

See https://developers.google.com/chrome-developer-tools/docs/javascript-debugging#breakpoints-on-javascript-event-listeners

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top