cancel
Showing results for 
Search instead for 
Did you mean: 

how to create input fields dynamically

Former Member
0 Kudos

Hi all in the link to action button i have written the follwing code to create input fields dynamically but i am getting the error can u correct where i went wrong

"here 'cost_copyto is the node name costcenter function,description are the field names and input1,2,3 is the id given for input fields but when executin i am getting following error - view is unknown not defined by a data statement.

following is the code written under link to ACTION

data: lr_INPUT1 type ref to CL_WD_INPUT_FIELD.

DATA: LR_INPUT2 type ref to CL_WD_INPUT_FIELD.

DATA : LR_INPUT3 type ref to CL_WD_INPUT_FIELD.

data: lr_container type ref to cl_wd_transparent_container.

data: lr_flow_data type ref to cl_wd_flow_data.

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

lr_input1 = CL_WD_INPUT_FIELD=>NEW_INPUT_FIELD( ID = 'INPUT1'

bind_value = 'cost_copyto-COSTCENTER'

).

lr_input2 = CL_WD_INPUT_FIELD=>NEW_INPUT_FIELD( ID = 'INPUT2'

bind_value = 'cost_copyto-FUNCTION'

).

lr_input3 = CL_WD_INPUT_FIELD=>NEW_INPUT_FIELD( ID = 'INPUT3'

bind_value = 'cost_copyto-DESCRIPTION'

lr_flow_data = cl_wd_flow_data=>new_flow_data( element = lr_INPUT ).

lr_container->add_child( lr_INPUT1 ).

lr_flow_data = cl_wd_flow_data=>new_flow_data( element = lr_INPUT ).

lr_container->add_child( lr_INPUT2 ).

lr_flow_data = cl_wd_flow_data=>new_flow_data( element = lr_INPUT ).

lr_container->add_child( lr_INPUT3 ).

endmethod.

Thanks & Regards,

Naveen

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Your binding values also don't look correct.

However I would raise the question as to why you are creating these dynamically at all. You seem to have a fixed definition of these fields. If you just want them to appear under certainly conditions, why not insert them all at design time and then control the visibility of the fields by binding additional context attributes (or attribute properties) to the visible property.

Former Member
0 Kudos

HI Thomas,

i have created a group name- blank and for the visibility property of this group i have binded the attribute visible-wdy_boolean attribute. now in this group there is link to action ui element in that action if user click on that again group name- blank should be appeared. so for that in that link to action i have written the following code

wD_CONTEXT->SET_ATTRIBUTE(

NAME = 'BLANK_VISIBLE'

VALUE = ABAP_TRUE ). but it is not performing any action when we click on this link to action.

can u tell me where i went wrong.

Thanks & Regards,

Naveen

gill367
Active Contributor
0 Kudos

Hi

You can do so by using these steps.

1. Create an attribute of type WDUI_Visibility in the view say its name as vis.

2. Go to the layout, You will be having group. bind its visiblity property to the attribute vis (created in the first step)

3. go to the eventhandler of the action bound to link to action of in UI.

4. there write the following code to make the group visible

wd_context->set_attribute(

name = 'VIS'

value = CL_WD_GROUP=>E_VISIBLE-VISIBLE

).

Former Member
0 Kudos

Hi Sarbjeet,

can u tell this point what you have mention

go to the eventhandler of the action bound to link to action of in UI.

i will create an attribute vis

my group name is blank_visible

for this group i have binded the vis attribute to the visibility property.

now in this group only i have an link to action in that action u want me to write the code what you have send

go to the eventhandler of the action bound to link to action of in UI.- can u tell me this point exactly .

Thanks & Regards,

Naveen

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The key here is that Visiblity isn't Boolean.

visible

Visibility of the interface element.

This property can be personalized both by a user and by an administrator.

Values

Description

Can be set using personalization

NONE

The UI element is not visible on the screen and takes up no space.

Yes

VISIBLE

The UI element is displayed on the screen.

No

You shoudl use WDUI_VISIBILITY and the constants from CL_WD_UIELEMENT=>E_VISIBLE.

gill367
Active Contributor
0 Kudos
now in this group only i have an link to action in that action u want me to write the code what you have send

yes there only.

thanks

Former Member
0 Kudos

Hi sarbjeet,

as you said that i have done but it is not displaying any input fields dynamically and more over it is hiding the visibility of the button

my requirement is in a group i have 3 input fields and 1 linktoaction and i click on that link again a group of 3 input fields should appear this is my requirement. can u send me the sample code how to do achieve this functionality

3 input field names copyto description function nodename is copyto- costcenter (COSTCENTER), function(/BIC/CSERVAREA), description(TXTSH).

Thanks & Regards,

Naveen

Former Member
0 Kudos

Hi Naveen,

U already posted same question and closed also..

In below link discussed same requirement.. there code is for creating 10 inputfields on button click.. yours 3 inputfields

Just do some modifications accordingly..

.

Thanks,

Kris.

gill367
Active Contributor
0 Kudos

What if the link is clcked once again. will three more input fields will eb created.

in this way on each click you want to generate new input fields.

i guess that is not the case as you are binding them to three static attributes.

then wts the use of creating them again dynamically.

you have three input fields and one link in the group

now on the click of link you want to create three more input fields.

i hope first three input fields are pointing to different attributes and newly created are pointing to different.

ok now coming to the process of acheving as told earlier.

create two groups

in one group have this first 3 input fields and link

and in the second one group2 create 3 more input fields and bind them to these attribute that you said.

now create the attirbute with visiblity property and bind it to second group's visiblity property

and in the eventhandler make it visible by setting the value.

thanks

sarbjeet singh

Answers (1)

Answers (1)

gill367
Active Contributor
0 Kudos

you cannot write such code of modifying the view in action event handler.

you need to write it in wddomodify.

create some context attribute of type string or boolean .

and set its value to some specific value in the eventhandler and then

in the wddomodify check the value of the same if true then create input fields.

thanks

sarbjeet singh

Former Member
0 Kudos

Hi Sarbjeet,

can u tell me these points what you said

and set its value to some specific value in the eventhandler and then

in the wddomodify check the value of the same if true then create input fields.

and kindly can u do changes to my code necessary where it is required.

Thanks & Regards,

Naveen