iFormBuilder JavaScript Tips & Tricks
Table of Contents
What is an email element?
The Email element allows you to send records to various email addresses when the data is synced.
Click here for information on the Email element and how to add one to your form.
How do I dynamically populate an email?
STEP 1. Add a Multi-Select element to your form with a data column name of my_multi.
STEP 2. Attach your Option List. In this example, we'll be using an Option List that includes the following choices:
- Option 1
- Option 2
- Option 3
STEP 3. Below your Multi-Select element, place a Text Area element with a data column name of text_copy.
STEP 4. In the Dynamic Value of the Text Area element, put the following: ZCDisplayValue_my_multi. This tells the element to use the Label of the element chosen instead of the Sort Order.
PLEASE NOTE: The Text Area element does not need to be visible to the end user. To hide the element on the user's device, simply put false into the Condition Value of the element.
STEP 5. Add an Email element and make sure the Send Email box is checked.
STEP 6. In the Dynamic Value of the Email element, put the following: replaceText(text_copy).
STEP 7. Click the Page Level Javascript icon.
STEP 8. From the Page Level Javascript page, place the below function into the Page Level JavaScript.
function replaceText(myText){
myText = myText.replace("Option 1","email1@domain.com, email2@domain.com");
myText = myText.replace("Option 2","email3@domain.com, email4@domain.com");
myText = myText.replace("Option 3","email5@domain.com, email6@domain.com");
return myText;
}
PLEASE NOTE: The Page Level JavaScript function takes the myText variable and replaces the Option 1, Option 2, or Option 3 with the specified email addresses and returns the text string of email(s).
STEP 9. Save your form.
STEP 10. Test the functionality on your device.
Download this form package to use as an example of how to dynamically populate your email element.
Comments
1 comment
What about for a PICK LIST choice? We've tested this solution to populate an email widget from a PICK LIST choice, and it appears to work. Would you recommend against this (if so, why)? Or should it be OK?
Please sign in to leave a comment.