cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable/disable the input fields based on the data entered/user action in the web dynpro abap?

former_member201541
Participant
0 Kudos

How to enable/disable the input fields based on the data entered in the web dynpro application abap?  If the user enters data in one input field then only the next input field should be enabled else it should be in disabled state. Please guide.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try this code.

First create a attribute with the name readonly of type wdy_boolean and bind it read_only property of input field of which is you want to enable or disable.

Next go to Init method.

Set the readonly value as 'X'.

DATA lo_el_context TYPE REF TO if_wd_context_element.
     DATA ls_context TYPE wd_this->element_context.
     DATA lv_visible TYPE wd_this->element_context-visible.

*   get element via lead selection
     lo_el_context = wd_context->get_element( ).

*   @TODO handle not set lead selection
     IF lo_el_context IS INITIAL.
     ENDIF.

*   @TODO fill attribute
*   lv_visible = 1.

*   set single attribute
     lo_el_context->set_attribute(
       name =  `READONLY`
       value = 'X').

After that Go to the Action  ENTER.


First read the input field ( first input field, which is value entered field) , next give a condition

if input value is not initial  then set the readonly value is '  '.


DATA lo_nd_input TYPE REF TO if_wd_context_node.

     DATA lo_el_input TYPE REF TO if_wd_context_element.
     DATA ls_input TYPE wd_this->element_input.
     DATA lv_vbeln TYPE wd_this->element_input-vbeln.

*   navigate from <CONTEXT> to <INPUT> via lead selection
     lo_nd_input = wd_context->get_child_node( name = wd_this->wdctx_input ).

*   @TODO handle non existant child
*   IF lo_nd_input IS INITIAL.
*   ENDIF.

*   get element via lead selection
     lo_el_input = lo_nd_input->get_element( ).
*   @TODO handle not set lead selection
     IF lo_el_input IS INITIAL.
     ENDIF.

*   get single attribute
     lo_el_input->get_attribute(
       EXPORTING
         name =  `VBELN`
       IMPORTING
         value = lv_vbeln ).

if lv_vbeln IS not INITIAL.


    DATA lo_el_context TYPE REF TO if_wd_context_element.
    DATA ls_context TYPE wd_this->element_context.
    DATA lv_visible TYPE wd_this->element_context-visible.

*  get element via lead selection
    lo_el_context = wd_context->get_element( ).

*  @TODO handle not set lead selection
    IF lo_el_context IS INITIAL.
    ENDIF.

*  @TODO fill attribute
*  lv_visible = 1.

*  set single attribute
    lo_el_context->set_attribute(
      name =  `READONLY`
      value = ' ' ).

former_member201541
Participant
0 Kudos

Thank You Raji, its working

Answers (4)

Answers (4)

former_member201541
Participant
0 Kudos

Thank you all for your help

Former Member
0 Kudos
former_member184578
Active Contributor
0 Kudos

Hi,

 If the user enters data in one input field then only the next input field should be enabled else it should be in disabled state.

here after entering the data in one input field, the user has to press Enter.

Create an attribute in context (say enable of type wdy_boolean) and bind the Read-only property of the input field to that attribute. Then create an action of OnEnter event of input field and set the attribute (enable) to abap_false to make it enable.

You can check this wiki for reference: Simple application to change properties of UI Elements during runtime in Web Dynpro ABAP - Web Dynpr...

Regards,

Kiran

harsha_jalakam
Active Contributor
0 Kudos

Hi ,

Create a attribute of type WDY_BOOLEAN and bind it to the input field readOnly property which has to be enabled or disabled.

Now on based the user input on first field , write logic on onEnter event for setting the attribute value, which is binded to second  input field.

If the input field has to be enabled then set the attribute's value as 'X', otherwise set its value as '  '.

Regards,

Harsha J

former_member201541
Participant
0 Kudos

Can u explain in more detail. I'm trying what u said but not getting the expected result. Please explain in more detailed manner. Thank You

harsha_jalakam
Active Contributor
0 Kudos

1. Create a separate node of type WDY_BOOLEAN and bind it to readOnly property of the input, which you want to enable / disable .

2. Now based on user input & your condition, set the value of that attribute accordingly(If the input field has to be enabled then set the attribute's value as 'X', otherwise set its value as '  '.). This piece of code must be written , onEnter even of the input field, where user is entering and based on input you want enable / disable the field.

harsha_jalakam
Active Contributor
0 Kudos

Do u enable / disable the field or do you want to hide/ show the filed based on user input?