cancel
Showing results for 
Search instead for 
Did you mean: 

How to default check checkboxes in a checkbox group?

Former Member
0 Kudos

Hi all,

I have placed a checkbox group UI Element on my view. I am able to get the selected check box and store values and perform other operations, by handling the onToggle event.

But i want to set the same check boxes again, when the user returns to that view (in WDDOMODIFYVIEW method). I couldn't find any suitable method in the class 'CL_WD_CHECKBOX_GROUP'.

Is there any way to default it....?

Regards,

Runal

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Runal,

I did try placing a CheckBoxGroup UI element on my layout, toggled a few checkboxes & then navigated to a 2nd view. I then re-navigated back to my first view. The toggled state of the checkboxes has been preserved properly. What exactly is your scenario when you say, "when the user returns to that view (in WDDOMODIFYVIEW method)."

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

I have 4 check boxes which are created from values stored in a table. For example ECC6, SRM, CRM, APO.

The user may select any or all of these and saves it. I store the value 'X', for each of these selected check boxes in database table.

So, when the user logs in again next time, i have to show the check boxes selected again, the ones he/she had saved when the last login happened.

Regards,

Runal

uday_gubbala2
Active Contributor
0 Kudos

Hi Runal,

The CheckBoxGroup UI element is nothing but a collection of the normal Checkbox UI elements. Therefore to set the selection or remove the selection for a particular checkbox you would first obtain the reference of that particular element by using the index & then use the method SET_SELECTED of the IF_WD_CONTEXT_ELEMENT object. Hope that this is clear for you now. So once you have managed to obtain the information about which checkboxes were selected you can then obtain the information about their context elements & initialize the checkBoxGroup with the same values again. Hope that this would help reach a solution.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Just as another hint, if you had a button & upon clicking it you wanted to achieve the select all checkboxes functionality then you would do something like in the code snippet below:

lv_idx = 1.
DO n TIMES.
     lo_el_mail_recipients = lo_nd_mail_recipients->get_element( index = lv_idx ).
     lo_el_mail_recipients->set_selected( abap_true ).
     lv_idx = lv_idx +1.
ENDDO.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Runal,

Since you said that you are saving the value for each of these checkboxes in the database table then you can easily code your desired functionality. Within your WDDOINIT method read the entries from the database. So now depending up on which row has the entry as checked you can easily fetch the context element corresponding to that index position. Say suppose you have the 4 options ECC6, SRM, CRM & APO as how you have said. If the database table has entries saying like SRM & CRM are checked then (assuming that you are displaying the 4 checkboxes in the same order as ECC6, SRM, CRM & APO) you would pass the INDEX values as 1 & 2 and fetch the references of the corresponding context elements. You would then just have to say:

lr_element = lr_node->get_element( index = '1' ).
lr_element->set_selected( abap_true ).

lr_element = lr_node->get_element( index = '2' ).
lr_element->set_selected( abap_true ).

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

Thanks a lot for the solution, it was spot on. Thanks a lot for the efforts.

Regards,

Runal

uday_gubbala2
Active Contributor
0 Kudos

Hi Runal,

You are welcome. Glad that I could help you reach the desired solution. I hadn't got to work with the CheckBoxGroup UI element earlier so working on your requirement was some sort of learning for myself!

Regards,

Uday

Answers (1)

Answers (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Runal,

When the user toggles with the checkboxes you can save the current state onto a context attribute of type STRING_TABLE. Later when you revisit the view you can may be try set the checkboxes to the same state using this attribute.

1) Create an Attribute SAVE_STATUS in Component Controller of type STRING_TABLE

2) Now in this Attribute (SAVE_STATUS) , you will be having all the indexes of CheckBox.

data:  Index type string,
           checked type string.

index = wdevent->get_string( 'INDEX' ).

checked = wdevent->get_string( 'CHECKED' ).

if checked = 'X'.

      APPEND index to WD_COMP_CONTROLLER->SAVE_STATUS.
endif.

Regards,

Uday