cancel
Showing results for 
Search instead for 
Did you mean: 

How to set cursor/focus on input field

santhosh_nagavalli
Participant
0 Kudos

Hi Experts ,

     I have ten input fields on view,all are mandatory fields  my requirement is after clicking on submit button if any of the input field is not entered

then cursor/Focus should be on that input field ,can anybody tell me the solution advance thanks.

Regards

Sandesh

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184578
Active Contributor
0 Kudos

Hi,

Are you displaying any error messages if the field is initial? If so, you cannot set focus on field as the focus will be shifted to message area. you can use report_attribute_error_message( ) method of message manger to highlight the input field(in red color, but no focus set).

If you want to set the focus without any error messages, use the below code

DATA: lr_elem TYPE REF TO if_wd_view_element.

      lr_view type ref to if_wd_view.

      lr_view ?= wd_this->wd_get_api( ).

   lr_elem = view->get_element( 'INP1' )." INP1 is the UI element ID of input field1

  lr_view->request_focus_on_view_elem( lr_elem ).

hope this helps,

Regards,

Kiran

santhosh_nagavalli
Participant
0 Kudos

Hi Kiran ,

    Thanks for quick response , yes if the field is initial i am displaying the error message . For

this method report_attribute_error_message( )  can you please tell me what should be passed in exporting parameters  Element and attribute name  . My requirement is to highlight the input field if the Input field is initial along with the error message .Advance Thanks

Regards

Sandesh

former_member184578
Active Contributor
0 Kudos

Hi,

Use the below code:


DATA lo_message_manager TYPE REF TO if_wd_message_manager.

* Get  Message manager

lo_api_controller ?= wd_this->wd_get_api( ). 

CALL METHOD lo_api_controller->get_message_manager 

    RECEIVING 

        message_manager = lo_message_manager. 

* Get the context element  

DATA lo_nd_node TYPE REF TO if_wd_context_node. 

DATA lo_el_elem TYPE REF TO if_wd_context_element. 

lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ). " node is name of your Context node

lo_el_elem = lo_nd_node->get_element(  ).

 

 

CALL METHOD lo_message_manager->report_attribute_error_message 

    EXPORTING 

        message_text   = 'Error Message' 

        element            = lo_el_elem 

        attribute_name = 'ATTR'.   " ATTR is the attribute name to which the input field is bound

hope this helps,

Regards,

Kiran

harsha_jalakam
Active Contributor
0 Kudos

Hi Sandesh,

In case if you are validating all the mandatory fields at the end,(at submit), its better to use cl_wd_dynamic_tool class for checking all the fields and get the error message.

www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/207e4467-227e-2e10-6fbb-e3a562038296?Qui...

Regards,

Harsha

ramakrishnappa
Active Contributor
0 Kudos

Hi Sandesh,

Please check the  below document, in which I have clearly described the steps involved in achieving your requirement.

Hope this helps you.

Regards,

Rama