cancel
Showing results for 
Search instead for 
Did you mean: 

How to set focus at UI element ?

danilo_henriques
Explorer
0 Kudos

Hello,

I've been trying to set focus at UI element(Input Field) but i can't get no results. When i click the button, the method is executed but nothing happens.

Here is my code:

DATA: l_api TYPE REF TO if_wd_view_controller.

l_api = wd_this->wd_get_api( ).

l_api->request_focus(

context_element= Elem_I_Zceldes_Desenv_Fun

attribute = 'BNAME' ).

Can someone help me?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Write in wddomodify() of view/

If init is the node name having attribute initwhich is bound to an input field and you want to set focus on it then following code works

DATA:

lo_node TYPE REF TO if_wd_context_node,

lo_element TYPE REF TO if_wd_context_element,

lo_view_contr TYPE REF TO if_wd_view_controller.

lo_node = wd_context->get_child_node( name = wd_this->wdctx_init ).

lo_element = lo_node->get_element( ).

********************************************************************************

*........ Step 1 : To set focus on field 'init'...............

********************************************************************************

if first_time = abap_true.

lo_view_contr = wd_this->wd_get_api( ).

lo_view_contr->request_focus( exporting context_element = lo_element

attribute = 'init' ).

endif.

danilo_henriques
Explorer
0 Kudos

Hi all,

thanks for your help. My problem is solved.

Former Member
0 Kudos

i got a focus on first input field. when user clicks on enter it should focus on next input field. I am not getting this. Plz help me how to do this

Former Member
0 Kudos

Hi Praveen,

Write below code on OnEnter Action of the First input field.

data: lr_elem type ref to if_wd_view_element.

lr_elem = view->get_element( <ID of the second input field>).

if lr_elem is bound.

view->request_focus_on_view_elem( lr_elem ).

endif.

Do the same kind of proccedure for remaining input fields. i.e. OnEnter event of the second input field, set the focus on third input field with corresponding ID and so on....

Thanks,

Prashant

Former Member
0 Kudos

Hi Prasanth,

I am getting "Cannot user NULL reference as object error at view".

Can you please tell me how to get the reference of the "view".

Thanks

Praveen

Answers (4)

Answers (4)

0 Kudos

Hi all,

the last Post is right.

You have in every method or action the possibility with if_wd_view_controller->request_focus( ) to set the focus to an element.

kind regards

Christian

Former Member
0 Kudos

Hi

try this

data: lr_elem type ref to if_wd_view_element.

lr_elem = view->get_element( 'IP_FIRSTNAME' ).

if lr_elem is bound.

view->request_focus_on_view_elem( lr_elem ).

endif.

IP_FIRSTNAME is the ID of my input field.

regards

chythanya

Former Member
0 Kudos

Hi Danilo

Try like this.

Here INP_PAR_LIFNR is the UI element id on the View

data: lv_v_elem type ref to if_wd_view_element.

lv_v_elem = view->get_element( 'INP_PAR_LIFNR' ).

if lv_v_elem is bound.

view->request_focus_on_view_elem( lv_v_elem ).

endif.

Regards

Naresh

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I've not used that method to set the focus before, so I can't say what might be wrong. However there is another API method of the View itself. You might try that:

[http://help.sap.com/saphelp_nw70/helpdata/EN/42/f74da548bc3255e10000000a1553f7/frameset.htm|http://help.sap.com/saphelp_nw70/helpdata/EN/42/f74da548bc3255e10000000a1553f7/frameset.htm]