cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Creation of input fields

Former Member
0 Kudos

Dear Guys,

I have a node name 'NodeA' with 10 attributes(a,b,c,d..j) in it.

When the add button is clicked , I want to display 10 inputfield for the 10 attributes of 'NODEA' to be dynamically created and displayed. so what coding should be written in the add buttons action....

Regards,

Shamila

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

s

uday_gubbala2
Active Contributor
0 Kudos

Hi Shamila,

I have a context node by name NODE & it has 10 attributes like NODE_1, NODE_2,... NODE_10 under it. All these attributes are of type STRING. So you just have to put the below code into WDDOMODIFYVIEW to get 10 input fields & labels displayed. These input fields would show any string that you have maintained for each attribute using the "Default Value" property.

METHOD wddomodifyview .
  DATA :  lr_container TYPE REF TO cl_wd_uielement_container,
	   lr_input_field TYPE REF TO cl_wd_input_field,
          lr_label TYPE REF TO cl_wd_label,
	   lv_attribute_name TYPE string,
	   lv_id TYPE string,
          lv_label_text TYPE string.


  CHECK first_time = abap_true.
  lr_container ?= view->get_root_element( ).

  cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
  lr_container->set_width( value = '50%' ).

  DO 10 TIMES.

    MOVE sy-index TO: lv_attribute_name,
		        lv_id,
                      lv_label_text.
" Figuring out the context attribute name to bind to the input field
" Since the node name is NODE & attributes are like ATTR_1, ATTR_2..
" The value to be bound would be like NODE.ATTR_1, NODE.ATTR_2....
"  Am condensing the string finally to avoid any gaps in between coz it would lead to shortdump

    CONCATENATE 'NODE.ATTR_'
  	      lv_attribute_name INTO lv_attribute_name.
    CONDENSE lv_attribute_name NO-GAPS.	  	

" Figuring out a unique id to be used for assigning to the input fields
" Am assigning id's with values like IO_1, IO_2, ... IO_10
"  Am condensing the string finally to avoid any gaps in between coz it would lead to shortdump
    CONCATENATE 'IO_'
  	      lv_id INTO lv_id.
    	
    CONDENSE lv_id NO-GAPS.

" Figuring out a unique text to be used for assigning to the label fields
" Am assigning text to labels like Label_1, Label_2, .. Label_10
"  Am condensing the string finally to avoid any gaps in between coz it would lead to shortdump

    CONCATENATE 'Label_'
                lv_label_text INTO lv_label_text.
    CONDENSE lv_label_text NO-GAPS.


    lr_input_field =   cl_wd_input_field=>new_input_field( id	     = lv_id
							        bind_value = lv_attribute_name ).

    lr_label = cl_wd_label=>new_label(  label_for  = lv_id
                                        text       = lv_label_text ).

    cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_label ).
    cl_wd_matrix_data=>new_matrix_data( element = lr_input_field ).
    lr_container->add_child( the_child = lr_label ).
    lr_container->add_child( the_child = lr_input_field ).
    CLEAR: lv_attribute_name,
           lv_id,
           lv_label_text.
  ENDDO.
ENDMETHOD.

Regards,

Uday

Former Member
0 Kudos

Hi Shamila,

you can do here one thing, create one more view with required input fileds and fire outbount plug to the newly created view where you have already created and binded the input fileds with the atribute.

Thanks,

Shaik Shadulla.

Former Member
0 Kudos

Do u want to create both Node and Input fields Dynamically .

If So first create Node using Node Info .Rather than adding Attributes dynamically create a structure containing attributes in the Data Dictionary

For Eg Struc_Node

fields A type char20,

fields B type char 20

For Eg : To Create Node under Context Node( Root Node).

data lv_node_info type ref to if_wd_context_node_info.

lv_node_info = wd_context->get_node_info( ).

CALL METHOD lv_node_info->add_new_child_node

EXPORTING

static_element_type = 'Struc_node

name = lv_node_name

is_static = abap_false

is_multiple_selection = abap_true

RECEIVING

child_node_info = lv_child_node_info.

And Add the

UI Elelements

for eg

CALL METHOD cl_wd_input_field=>new_input_field

EXPORTING

bind_value = lv_bind_text

id = 'INP_1'

length = 3

width = '25px'

RECEIVING

control = lv_input_field.

For the Alignment Purpose Create a transparent Container and add the Elements in it .so that u can control through the layout managers

Former Member
0 Kudos

Dear Vikranth ,

I want to create the Input fields only dynamivcally Dynamically.

I have created a node called 'NodeA' in the context and it has 10 attributes.

How to create inputs fields dynamically and bind the attributes which is already created ...

Regards,

Shamila

Former Member
0 Kudos

Hi,

Create only the Input Fields Dynmaically and bind the Properties to it.

lv_bind_text = 'NODE_NAME.ATRR1'.

CALL METHOD cl_wd_input_field=>new_input_field

EXPORTING

bind_value = lv_bind_text

id = 'INP_1'

length = 3

width = '25px'

RECEIVING

control = lv_input_field

lv_bind_text = 'NODE_NAME.ATRR2'.

CALL METHOD cl_wd_input_field=>new_input_field

EXPORTING

bind_value = lv_bind_text

id = 'INP_2'

length = 3

width = '25px'

RECEIVING

control = lv_input_field2.

Former Member
0 Kudos

Dear Vikranth ,

I have created MYNODEA with attribute A inside it and the conetxt is set with the attribute cardinatilty 0:n and selection 0:1.

Group GROUPDYN is also created.

I have added the following code,

data : lv_bind_text type string,

lr_container type ref to cl_wd_uielement_container,

lv_input_field type ref to CL_WD_INPUT_FIELD.

lr_container ?= view->get_element( 'GROUPDYN' ).

lv_bind_text = 'MYNODE.A'.

CALL METHOD cl_wd_input_field=>new_input_field

EXPORTING

bind_value = lv_bind_text

id = 'INP_1'

length = 3

width = '25px'

RECEIVING

control = lv_input_field.

cl_wd_grid_data=>new_grid_data( element = lv_input_field ).

lr_container->ADD_CHILD( lv_input_field ).

But I am getting the following error

"Adapter error in &VIEW_ELEMENT_TYPE& "INP_1" of view "Z_CC_REG.MAIN": Context binding of property VALUE cannot be resolved: Node MAIN.1.MYNODEA does not contain any elements

"

It is not able to identify my context.

Regards,

Shamila