cancel
Showing results for 
Search instead for 
Did you mean: 

Create toggle for Checkboxes dynamically

Former Member
0 Kudos

Hi Everybody,

i am looking for an example to create an action handler (set_on_toggle) for a checkbox dynamically? Until now i did not found any contributions about it. My purpose is to start a process after a checkbox is checked. I just created a Checkbox dynamically.

regards,

Sid

Edited by: Sid Mopo on Jan 13, 2009 4:44 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

pranav_nagpal2
Contributor
0 Kudos

Hi Sid,

Check the code below....

method ONACTIONCB2 .
 
    DATA lo_el_context TYPE REF TO if_wd_context_element.
    DATA ls_context TYPE wd_this->element_context.
    DATA lv_cb1 LIKE ls_context-cb2.
*   get element via lead selection
    lo_el_context = wd_context->get_element(  ).
 
*   get single attribute
    lo_el_context->get_attribute(
      EXPORTING
        name =  `CB2` " this is attribute which is bound to any check box
      IMPORTING
        value = lv_cb1 ).
 
 
 
  DATA lv_ip1 LIKE ls_context-ip1.
* get element via lead selection
  lo_el_context = wd_context->get_element(  ).
 
if lv_cb1 eq ABAP_FALSE. " if it is not checked
* set single attribute
  lo_el_context->set_attribute(
    EXPORTING
      name =  `IP1`
      value = ABAP_TRUE ). " enable an inputfield
 
ELSEIF lv_cb1 eq ABAP_TRUE. " if it is checked
* set single attribute
  lo_el_context->set_attribute(
    EXPORTING
      name =  `IP1`
      value = ABAP_FALSE ). " disable the input field
endif.
endmethod.

regards

pranav

Former Member
0 Kudos

Hi Pranav,

thanks! I don't know how to use the methods like set_on_toggle, map_on_toggle etc. dynamically in order to call an action like yours: ONACTIONCB2. I have no problem to handle the context.

regards,

Sid

arjun_thakur
Active Contributor
0 Kudos

Hi Sid,

Refer to the this code:

METHOD wddomodifyview.
  DATA: lr_container TYPE REF TO cl_wd_uielement_container,
        lr_checkbox TYPE REF TO cl_wd_checkbox,
        lr_node TYPE REF TO if_wd_context_node.
 
  CHECK first_time = abap_true.
 
  lr_container ?= view->get_root_element( ).
 
  cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
 
  lr_checkbox = cl_wd_checkbox=>new_checkbox( bind_checked = 'NODE.ATTR1' 
                                              bind_text    = 'NODE.ATTR2'
                                              ON_TOGGLE = 'NODE.ATTR3'   ).
 
  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_checkbox ).
  lr_container->add_child( the_child = lr_checkbox ).
ENDMETHOD.

Now create a node with three attribute (all of string type), use them in your code as given above. the name which you'll give to ATTR3, create an action with that name, then you'll be able to an ONACTION method for that event. Write your code in that.

I hope it helps.

Regards

Arjun