The Buffet Menu application illustrates the usage of the Deluge List function. The application comprises of a Menu form with multi-select fields that list the menu items in each food category. Selection of the food items for the buffet is subject to the following restrictions:
- Only a total of ten items can be chosen from the different categories.
- A minimum of one item must be selected from each category.
- Only three premium items can be included.
When the Menu form is submitted, the validate script is executed to validate the form data for the above said conditions. The script uses the list functions to validate the data.
Adding Deluge Script
1. Validate script to validate form data
Menu form ->actions ->on add ->submit ->on validate
actions |
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)
|
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))
|
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();
|
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 |
To install the application,
- Download the script file (.ds file)
- Install the application to your account.Click here to learn how to install using the script file (.ds file)