cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling and disabling check boxes in a table row depending on the other.

Former Member
0 Kudos

Hi WebDynpro Experts,

I have a Table in WebDynpro.

In that Table I have two Check Box Columns.

By Default Both Should be Enabled(Or in Editable Mode), and Both Should be UnChecked.

If the User Checks any one check box, the Other Check Box Should Be Disabled(Not in Editable Mode), It Should be enabled If the User UnChecks the CheckBox which he Checked.

This is Just Like, to give the user to select

Any one option, at the same time he is not authorised to select both the options.

But user can choose no option(Unchecking of both the Check Boxes).

I need the above functionality in a normal table.This is for Approving(First ChkBx) and Rejecting(Second ChkBx) the time sheet entries of the subordinates by the Project Manager.

Can any one Give me the Solution Reg This.

I would be most Thankful for the help.

Thanks and Regards

Meshack Appikatla

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This is pretty simple requirement and without any coding and just by binding the right attributes you can achieve this functionality.

You must be having 2 attributes bound to noth your checkboxes.( e.g 'CHK1' and 'CHK2' ).

Just make sure that both these are of type Boolean.

Suppose your Checkbox1's checked property is bound to CHK1 and Checkbox2's checked property is bound to 'CHK2'

Now just bind the readonly property of the Checkbox1 with 'CHK2' and readonly propery of Checkbox2 with 'CHK1'.

This is it, your are done. No coding is required.

Regards,

Radhika.

Edited by: Radhika Vadher on May 29, 2009 7:53 AM

uday_gubbala2
Active Contributor
0 Kudos

Hi Radhika,

Thanks for suggesting the easier approach. This is a lot easier as how you said but then again your approach doesn't work out completely.... Surprised? I guess you haven't tried implementing the same. Suppose you toggle the checkbox in column 1 the state of the 2nd checkbox doesn't change and vice versa. I guess this is because the system doesn't perform any roundtrip unless there is any action associated with the "onToggle" event of the CheckBox. Try associate an action with the onToggle event & leave it as empty. Do this for both the 2 checkboxes then your approach would work out.

So yes your suggestion is better & does end up in no coding & using 2 lesser context attributes. But you just have to make a small correction to it as how pointed out.

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

Yes no doubt we will have to implement the event for both the checkbox.I missed out on mentioning that point. We need to just create one action for the onToggle event and use the same for both the checkboxes, but with absolutely no code.

Uday, I had tried this approach with ALV and i had to implement the onClick event for that.

You are correct. But i was happy to use this approach as we could cut down on so much of coding

Regards,

Radhika.

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi All

Thanks a Lot for helping me in completing this task.

My Problem was Resolved.

Thanks

Meshack Appikatla.

Former Member
0 Kudos

.

uday_gubbala2
Active Contributor
0 Kudos

Coding in ONACTIONONTOGGLE_CHECK2:

method ONACTIONONTOGGLE_CHECK2 .
  data: lr_element type ref to if_wd_context_element,
        wd_node type ref to if_wd_context_node,
        lv_value type abap_bool,
        lv_index type i value 0.
        
*** Obtain the desired context element
  lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).

*** Fetch info about whether the checkbox is getting checked or unchecked
  lr_element->get_attribute( exporting name  = 'CHECK2'
                             importing value = lv_value ).

*** Fetch info about the row in which the checkbox has been toggled
  lv_index = lr_element->get_index( ).

*** Use the index & context element reference obtained to toggle the editability of the 1st checkbox
  wd_node = wd_context->get_child_node( name = 'SFLIGHT' ).

  if lv_value = ''.
    wd_node->set_attribute( exporting index = lv_index
                                      name  = 'READONLY1'
                                      value = '' ).
  else.
    wd_node->set_attribute( exporting index = lv_index
                                      name  = 'READONLY1'
                                      value = 'X' ).
  endif.
endmethod.

uday_gubbala2
Active Contributor
0 Kudos

Now comes the important part. I create actionhandlers for event "onToggle" of the checkboxes. i have eventhandler ONTOGGLE_CHECK1 for the 1st checkbox & eventhandler ONTOGGLE_CHECK2 for the 2nd checkbox.

Its the coding within these eventhandlers that achieves your desired functionality.

Coding in ONACTIONONTOGGLE_CHECK1:

method ONACTIONONTOGGLE_CHECK1 .
  data: lr_element type ref to if_wd_context_element,
        wd_node type ref to if_wd_context_node,
        lv_value type abap_bool,
        lv_index type i value 0.
        
*** Obtain the desired context element
  lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).

*** Fetch info about whether the checkbox is getting checked or unchecked
  lr_element->get_attribute( exporting name  = 'CHECK1'
                             importing value = lv_value ).

*** Fetch info about the row in which the checkbox has been toggled
  lv_index = lr_element->get_index( ).

*** Use the index & context element reference obtained to toggle the editability of the 2nd checkbox
  wd_node = wd_context->get_child_node( name = 'SFLIGHT' ).

  if lv_value = ''.
    wd_node->set_attribute( exporting index = lv_index
                                      name  = 'READONLY2'
                                      value = '' ).
  else.
    wd_node->set_attribute( exporting index = lv_index
                                      name  = 'READONLY2'
                                      value = 'X' ).
  endif.
endmethod.

uday_gubbala2
Active Contributor
0 Kudos

I fill my table with some sample data for displaying using the below logic which doesn't in any way affect your functionality. You can fill it in anyway.

method WDDOINIT .
  data: wd_node type ref to if_wd_context_node,
        lt_sflight type wd_this->elements_sflight,
        wa_sflight type wd_this->element_sflight.

  wd_node = wd_context->get_child_node( name = 'SFLIGHT' ).

  select carrid
         connid
         fldate
         price from sflight into corresponding fields of table lt_sflight.

  wd_node->bind_table( new_items = lt_sflight ).
endmethod.

uday_gubbala2
Active Contributor
0 Kudos

Hi Meshack,

I am anyways giving you the code by which you can realize your checkbox functionality. Suppose i have a node by name SFLIGHT and am displaying the CARRID, CONNID, FLDATE & PRICE fields data. In addition to this I have 2 columns which am displaying as checkboxes. I have corresponding context attributes CHECK1 & CHECK2 of type ABAP_BOOL. In addition to these 2 boolean attributes I have 2 more ABAP_BOOL attributes which am using to control the editability of the checkboxes. I have named these attributes as READONLY1 & READONLY2.

The "checked" property of my first checkbox is ound to CHECK1 & the "checked" property of 2nd checkbox is bound to CHECK2.

Similarly the "readonly" property of 1st checkbox is bound to READONLY1 & the "readonly" property of 2nd checkbox is bound to READONLY2.

uday_gubbala2
Active Contributor
0 Kudos

Hi Meshack,

This would lead to an unnecessary complication in coding. The easier way would be to provide a drop down in 1 of the columns with the values as "Approve" & "Reject". This way it would not only be simple but also you can easily achieve the mutually exclusive functionality.

Regards,

Uday