Skip to Content
avatar image
Former Member

Dynamically delete an input field

Hi all,

I have a set of 5 input fields added dynamically previously. ( Input fiekd generated by code method). The 5 input fields user input value is binded to context node. Beside each input field, there is a delete button. If I want to delete the 2nd input field by pressing the 2nd delete button, how do I code it? There is 2 steps here right? Delete the selected context element and ui element.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Jun 16, 2011 at 09:25 AM

    yes, you are right.

    save the view instance in the view attribute. when the button is pressed, delete the UI element and then delete the context element.

    For this purpose , it is handy to have a context attribute containing the id of each dynamic input field,so that you can easily remove the UI element using its id.

    You can also make the creation of the UI element method generic, which read the context element and construct the UI layout. In that case you can just delete the context element and call this generic method.

    This method should use the reset_view method of the if_wd_view to delete all dynamic UI elements.

    Build the Dynamic layout once again based on the context.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 16, 2011 at 11:16 AM

    1. Create a controller variable (in Attributes Tab) - MR_VIEW type ref to IF_WD_VIEW

    2. in the WDDOMODIFYVIEW, store the VIEW instance to MR_VIEW

    wd_this->mr_view = view.

    3. in the button's action handler method write the code to delete the input field

    data: lr_container type ref to cl_wd_transparent_container.

    lr_container ?= wd_this->mr_view->get_element( 'ROOTUIELEMENTCONTAINER' ). "Containers name

    lr_container->remove_child(

    id = 'INPUT_FIELD1' "Inputfield id

    ).

    Hope this helps.

    BR

    Saravanan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hey Saraa,

      I have a set of ui elements here (text labels with the input fields). There are 2 sets of ui elements. I click on the delete button for 2nd set. It gave me a dump error. 'Adapter error in INPUT_FIELD "INP_002_BANK_ACCOUNT" of view "v_name" Context binding of property value cannot be resolved. Element with index 2 does not exist; context node: v_infotype9.1.infotype9_render

      What could it be? This is how i do it. When I click delete button, it send indicator 'x' to wddomodifyview to indicate a delete action has been performed

      In the wddomodifyview:

      If wd_this->remove = 'X'.

      data ui_id type string.

      ls_container ?= view->get_element( 'TCO_NAME' ).

      " remove text view ui

      concatenate 'TXV_' wd_this->remove_ui_index '_BANK_ACCOUNT' into ui_id.

      ls_container->remove_child( id = ui_id ).

      clear ui_id.

      " remove input field ui

      concatenate 'INP_' wd_this->remove_ui_index '_BANK_ACCOUNT' into ui_id.

      ls_container->remove_child( id = ui_id ).

      clear ui_id.

      ..............

      "remove selected context elements

      lo_node = wd_context->get_child_node( name = if_v_main=>wdctx_context_name ).

      lo_elem = lo_node->get_element( 2 ).

      lo_node->remove_element ( lo_elem ).

      wd_this->remove = space.

      ENDIF.

  • avatar image
    Former Member
    Jun 17, 2011 at 03:48 AM

    Hello,

    I dont see any problem with your delete code.

    any reason for deleting the second element of the context node? If I'm not wrong your context will have only one element. isnt it?

    BR Saravanan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Saraa,

      Right now I am very confused about the indexing here. You see there are 3 type of indexing here which must tally with each other in the deleting and adding part.

      1. The internal table which consist my input field values.

      2. The context elements which consist my input fielkd values.

      3. The ui element index it self.

      Say there is 4 set of input fields here. If I delete the 2nd set. I need to delete the ui elements with the corect id pointing to 2nd set. In addition, I need to delete the 2nd set of info in my internal table here and the 2nd index of the context element right? I cannot be having 3 sets of ui elements while there are 4 sets of context elements there.

      If I press add button to add another new set of ui elemnents, what is the index of the context elements then?

  • avatar image
    Former Member
    Jun 17, 2011 at 04:36 AM

    Hello Siong,

    for your use case, the context node cardinality should be 1..1 and there should be always one element in the context node. whenever a new input field is added, create a new attribute in the context node and bind the same to the input field.

    whenever the inputfield is deleted, then just remove the attribute from the context node.

    the context node of cardinality 0..n/1..n will come into picture only if you are displaying Table UI element/ Collection of data. I believe this is not your use case. you are displaying flat set of input fields.

    BR

    Saravanan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Saraa,

      Thanks for the reply. However the indexing issue is perplexing. I am still getting this sort of dump from time to time after clicking delete and add button a couple of times:

      'Adapter error in INPUT_FIELD "INP_002_BANK_ACCOUNT" of view "v_name" Context binding of property value cannot be resolved. Element with index 2 does not exist; context node: v_infotype9.1.infotype9_render

      So I came out with another solution but there will be dump too if clicking too many times delete and adding. It seems the program lost track of the indexing. But this time the dump will be something like : INPUT_FIELD "INP_002_BANK_ACCOUNT" of view "v_name already exist! Just sort of compromising the to have fewer dumps.

      What I did was:

      1. Delete and re-arrange my itab ( in delete action )

      2. Remove all UI elements (wddomodifyview)

      3. Invalidate all context elements (wddomodifyview)

      4. Rebind the context with the re-arrange itab (wddomodifyview)

      5. Re-render the UI elements with the re-arrange itab (wddomodifyview)

  • avatar image
    Former Member
    Jun 21, 2011 at 04:33 AM

    What I did was:

    1. Delete and re-arrange my itab ( in delete action )

    2. Remove all UI elements (wddomodifyview)

    3. Invalidate all context elements (wddomodifyview)

    4. Rebind the context with the re-arrange itab (wddomodifyview)

    5. Re-render the UI elements with the re-arrange itab (wddomodifyview)

    Add comment
    10|10000 characters needed characters exceeded