cancel
Showing results for 
Search instead for 
Did you mean: 

Create dynamically a number of Input Fields

Former Member
0 Kudos

hi all,

one issue about creating dynamically a range of Input fields:

i have one sap.ui.layout.form.FormContainer.

at first i want to have one Input field in it. if this field is filled, i want to have a new one below, which is empty, and the cursor should be set to the new field.

so i know that there is an function addContent for the formcontainer, so i can listen to the changeEvent of the Input field, if this is filled i will add a new Input field.

at first: is this a good solution or is there any recommended way from SAP?

second: if i will implement it this way, how can i read the data from this "array" of input fields?

third: how can i set focus on input field in sapui5?

thanks for help!

Regards,

Alex

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

1) Solution sounds good to me

2) You can do it in multiple ways:

  • you can use content aggregation from FormContainer
  • you can access Input field by id (you would need to follow some kind of convention when giving id to newely created field, like "inputField" + count, count ++)
  • you can use RowRepeater (not sure though how it looks in FormContainer) and use a model for bining

3) SAPUI5 SDK - Demo Kit From my experience element.focus() works just fine

Former Member
0 Kudos

hi Maksim,

thanks for your reply. only two points:

  • content aggregation from Form Container: if i want to have an textarea in the form container, and under it, i want my range of dynamic Input fields. how is this possible with content aggregation? could you give me an example?
  • does rowrepeater works with sap.m library?

br Alex

Answers (1)

Answers (1)

Former Member

Hi Alexander.

The approach doesn't sound robust. Say the user fills the input in field1, fileld2 will be created. Then the user fills input in filed2, field3 will be created. Now, what if the user deletes the input in field1 ?You have to do a manual validation of the fields in the end anyhow! For this, you can create all the fields initially and do validations of the fields in the end say when you click on submit button which is a simpler and most preferred way.

Regards

Sakthivel

Former Member
0 Kudos

hi,

yes this is correct, but the problem is that the user could fill n-fields. and how can i define fields, when i do not know the number?

br alex

Former Member
0 Kudos

Sorry, thought you're scenario was only about creating number of input fields. If even the range has to be calculated then your approach sounds good.