Adding Deluge Script
1. Validate script to validate form data
Menu form -> actions -> on add -> submit -> on validate
actions { on add { submit ( type = submit displayname = "submit" on validate { if ((input.Main_course.size() + input.Starters.size()+input.Desert.size()+input.Soups.size())> 10) { alert "Altogether only 10 items can be selected"; cancel submit; } if ((((input.Main_course.size()< 1) || (input.Starters.size()< 1)) || (input.Desert.size()< 1)) || (input.Soups.size()< 1)) { alert "Atleast one item must be selected from each category"; cancel submit; } totalList = List(); totalList.addall(input.Main_course); totalList.addall(input.Starters); totalList.addall(input.Desert); totalList.addall(input.Soups); noOfPremium = 0; for each elem in totalList { if (elem.contains("-- Premium")) { noOfPremium = (noOfPremium + 1); } } if (noOfPremium > 3) { alert "Only three premium items are allowed"; cancel submit; } } ) } |
Code Explanation
a. In the following code, the If condition sums up the number of items in each list using the <list>.size() funtion. If the total items selected exceeds 10, an alert message is displayed and the submission is canceled.
if ((input.Main_course.size() + input.Starters.size() + input.Desert.size() + input.Soups.size()) > 10) { alert "Altogether only 10 items can be selected"; cancel submit; } |
b. In the following code, the If condition checks it at least one item is added in each category using the <list>.size() funtion. If not, an alert message is displayed and the submission is canceled.
if ((((input.Main_course.size() < 1) || (input.Starters.size() < 1)) || (input.Desert.size() < 1)) || (input.Soups.size() < 1)) { alert "Atleast one item must be selected from each category"; cancel submit; } |
c. In the following code,
- A new list named totalList is created.
- The <list>.addall deluge task adds the elements in the given list to the totallist.
- Each element in totallist is iterated to check for the total number of premium items ordered. If the premium items exceed 3, the. is used to add the items in the list to a list If condition sums up the number of items in each list using the <list>.size() funtion. If the total items selected exceeds 10, an alert message is displayed and the submission is cancelled.
totalList = List(); totalList.addall(input.Main_course); totalList.addall(input.Starters); totalList.addall(input.Desert); totalList.addall(input.Soups); noOfPremium = 0; for each elem in totalList { if (elem.contains("-- Premium")) { noOfPremium = (noOfPremium + 1); } } if (noOfPremium > 3) { alert "Only three premium items are allowed"; cancel submit; }
|
2. On user input script
The on user input script is executed when you select/change the value of a field in your form. The script calculates the total number of items selected and displays it in a Note field. This script is added to all the multi-select list fields.
Desert ( type = list values = {"Italian delight (Cake)", "Chocolate Opera (Cake)", "Ambrosian delight (Ice Cream)", "Jumbo delight (Ice Cream)", "Pista Pasta (Ice Cream) -- Premium"} on user input { input.plain1 = ("<b><ul>No of items selected:" + ((input.Main_course.size() + input.Starters.size() + input.Desert.size() + input.Soups.size()))) + "</ul></b>"; } |