on 03-30-2015 1:05 PM
I have give focus for input field particularly one input field. I tried someway but that's not working. please assist me.
Hi Venkatesh,
SAPUI5 provides mechanisms for observing the moving focus in an application page for controls. This information is then preserved for refocusing elements after
rerendering. The focus triggers event firing. However, due to the high degree of flexibility in control rendering,
a functionality tailored to the respective controls is required. For this, the framework provides helper functions for the implementation of focus handling.
Each control provided by the SAPUI5 framework has its own behavior for focus handling, depending on the functionality that is provided by the control.
Complex controls and their embedded content constitute the highest level of complexity.
The base class for elements (Element.js) provides the following four methods to support the implementation of focus handling:
Element.getFocusDomRef()
Once a visible element is rendered, it has a Document Object Model (DOM) representation. The root DOM node can be accessed by using the method getDomRef()
on the element. The root DOM node is the default focused DOM node. After rendering, when a control is supposed to be focused, the framework asks the control for its
focus DOM node by using the getFocusDomRef() method. If the root DOM node does not represent the element that should have the focus, you have to return another DOM
node by overriding the getFocusDomRef() method.
Element.focus()
The focus() method sets the focus on the element. This is done using the focus DOM node.
Element.getFocusInfo()
For some controls, it is even more difficult to apply the focus once the control has been rerendered. List controls, for example, have their own internal focus
handling and set the focus on the different items. A data table moves the focus over a matrix of cells. The requirement is that a control can apply the focus to
its exact previous position after rerendering. In cases where the SAPUI5 rendering mechanism fails to find the correct element after rendering (for example because
it does not have an ID or the ID changed), override the getFocusInfo() method and serialize the focus state into a JSON object and return it. Before rendering, the
render manager calls this method for the element instance and stores this information for future use. After rendering, it calls the applyFocusInfo() methodand passes
back the serialized object. This is not only useful for focus information: The exact cursor position of a TextField control, for example, can also be stored in such an object.
Element.applyFocusInfo(oFocusInfo)
The applyFocusInfo() method applies the focus to the element after rerendering. You use this method if a different behavior is expected for the element.
I hope it's useful to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
$(document.ready(function()
{
sap.ui.getCore().byId("inputId").focus();
}));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to set a timeout:
jQuery.sap.delayedCall(0, this, function() {
this.byId("input").focus()
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
use a jquery focus method.
$("id-of-the-textfield").focus()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
here is the sample working code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried the focus() method as mentioned in the API?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> var input = new sap.m.input("",{placeholder:"Name"});
> input.focus();
Price question: WHERE is the Input being displayed at the time you call .focus() ?
Make sure to call focus when the DOM is actually there, including the DOM of the Input.
Some suggestions are already floating around, but to really help one needs to know the exact use-case better. In a controller's init() method is not a good place (before rendering). The afterRendering hook will work, but I doubt you want to have the focus always only in the Input, and rerendering of the View will then put it there.
Regards
Andreas
User | Count |
---|---|
89 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.