zerion

Scroll
Follow

How do I Check for Duplicates in a Multi-Paging Subform?

iFormBuilder Tips and Tricks

what is a multipaging subform

A Multi-Paging Subform allows users to capture as many records as they need for a particular Subform element.  For instance if you are using a Subform for images, setting the subform Link Mode to "Multiple" will allow you take many photos, each photo creating their own Subform record.

multiple page subform


why check for duplicates multipaging subforms

There may be times when you are using a Multi-Paging subform and you want to check that a specific field doesn't contain the same value twice within all of the subform records. Below are the steps to ensure a user enters a unique value in each record for the defined element.


how to check for duplicates multipaging subforms

PLEASE NOTE: In order to perform this operation you must have selected Multiple as the Link Mode for your Subform element as shown above.

In this EXAMPLE the following forms were used:

Label: Test Duplicates Parent

Table Name: test_duplicates_parent

     Label: Test Duplicates Subform

     Table Name: test_duplicates_sub

     Element we want to check duplicates for: my_id

     **my_id has a Dynamic Value of: ""

     **The Test Duplicates Parent is linking to a Multi-Paging Subform Element on the parent called my_sub_element


STEP #1. To start, add the following code to the Page Level Javascript of the Parent Form.

Page Level Javascript:

function iformAppendString(myArray, myElement) {
var total = '';
for (var i = 0; i < myArray.length; i++) {
if (total.length > 0)
total += ' , ';
total += myArray[i][myElement];
}
return total;
};

page level javascript

**More information on this function can be found here


STEP #2. Add a Text Area field on the parent form above the Subform Element called my_text_area with the following Dynamic Value: 

my_text_area = iformAppendString(test_duplicates_parent.my_sub_element, 'my_sub_text')

text_area.png


**The my_sub_text is the name of the element in the Subform you want to check duplicates for.


STEP #3. Add a Text Field beneath the subform element called: not_found.  To alert the user if a duplicate entry was made, apply the following Dynamic Value to the Text element:

not_found=my_text_area.search(my_id)

**This will return -1 if the value is Not Found and will return anywhere from 0-# depending on how many characters that match are found. 

Also apply a condition value of: false

**This will hide it from the device.

not_found.png


STEP #4. Add another element and check the "Required" property BEFORE choosing the Input type as a Label.  

Apply the following condition value to this form:  not_found!=-1 && my_id!=""

**This condition value keeps the required label hidden while all entries are unique. If a duplicate is detected, the label will appear blocking the parent record from being completed.

required_text.png

required_label.png

 


STEP #5. Test your form multiple times to ensure it is the functionality you would like.


related_articles.png

    Was this article helpful?
    0 out of 0 found this helpful
    Have more questions? Submit a request

Comments

Powered by Zendesk