Skip to main content

Constructor Fields in Collection

Allows you to set a value in a collection field if no input is added in the field by the users so that no field is left empty in the output.


1. Accessing Constructor Settings

To access Constructor settings go to the Collection panel in the Left Toolbar of the builder and open the settings of the collection in whose fields you want to apply constructors by clicking the settings icon. A dialogue box containing all setting options to modify the collection will open. Click on "Constructor" once to open the constructor settings.

DrapCode Builder Collection Constructor

2. Creating a Constructor

To create a constructor follow below steps:

Step 1: Create a Constructor

To create a constructor in a collection field, open the Constructor settings of a collection where all the collection fields will show. Now add the Constructor name and one by one add constructors to as many collection fields as you want. Don't forget to click the Save button at the end.

DrapCode Builder Collection Constructor

Step 2: Bind the Constructor

Constructors can only be added to the Save Collection event. Therefore, go to the Events panel and create a save collection event by clicking Add New Action button. Select the collection, choose the constructor and click the Save button.

You can also add a constructor in an existing save collection event by opening the settings of the event that contains the event action to Save Collection as shown in the example below.

DrapCode Builder Collection Constructors

Step 3: Preview or Publish the Page

Now bind the collection as well as the Save Collection event with a collection form and open the page in the preview or publish mode.

DrapCode Builder Collection Constructors

Step 4: How the Constructor Works?

Fill the form but leave the fields in which the constructor is applied empty and submit it.

Go back to the builder and open that collection to check if the empty fields are not blank and contain the content while creating the constructor.

DrapCode Builder Collection Constructors

3. Default Constructor

If you don't want to add a custom constructor you can create and add a default constructor that automatically gets created by the Java compiler.