Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Multiple instances of a Form fragment on a form - input data replicated in each instance

Avatar

Level 2

We have an address fragment that we have pulled in twice to a form (address and work address) When we enter the postcode in the 1st instance the postcode field the second instance field renders the same value. We have tried this with and without a schema for the form. Where we have used a schema we have bound each fragment to the specific part of the data model.

IainClucas_0-1665157945036.png

 

When it rendered and you enter data its it repeated in the field for the other fragment

IainClucas_1-1665158012420.png

The generated input fields have different id and name attributes.

 

Does anyone know if there is a mechanism to address this? 

4 Replies

Avatar

Level 4

Check the data binding for the fields and subform if any.

share your form if possible.

 

Avatar

Employee Advisor

@IainClucas 

This is expected as fields from two fragment instances will have the same bindings and, thus, the same data based on the value from the DOM. Basically, if you create a section that is repeating, then the field names will be the same, and there will be multiple instances of the same field. The repeating section will create multiple copies of the inner elements (fields), and all will have the same name, but the index will be different.

 

A better approach is to build one fragment for the same section that will repeat multiple times instead of creating the same section/field multiple times in design time.

 

Avatar

Employee Advisor

@IainClucas There are two way why the data will be replicated.

 

1. The name of the object is the same

2. The binding of the two is the same.

 

while the 2 can be used in the specific case where the actual need is to have the same value in another field.

 

Solution- all you have to do is check the binding field and change it so that it's different.

 

Mayank_Gandhi_0-1665402203592.png

 

Avatar

Level 2

Hi - thanks all for the responses and apologies for delay (I have been away). In our instances we do not tend to work with an initial schema so there is nothing to bind the fields. I have created a crx package with a simple form and fragments that acts in the way I have described. If I can find a way to upload or share I will. I have tried the form as it and also added a bind ref to each fragment (even through I am not using a data model)

 

The way this client works is that the forms are built ad-hoc and then when they are happy with them we generate a schema from the form itself for passing to the downstream service team so they know what format we will be sending to them. I am guessing that it could be possible to retrospectively attach that schema to the form and add the bind refs, but I have not tried this yes.

 

I have shared the package on a google drive.

Multi-instance-form-fragment.zip