Buffet Menu
Buffet Menu 应用程序包括一个带有多选字段的菜单表单,列出每个食物类别中的菜单项。
选择自助餐食物受到以下限制:
- 从不同类别中总共只可选择十项。
- 必须从每个类别中选择至少一项。
- 只可包括三个优惠项目。
添加到应用程序的 Deluge 脚本
1.验证脚本
当提交菜单表单时,执行验证脚本以验证表单数据是否符合上述条件。脚本添加到菜单表单的“动作 - 添加时 - 验证时”部分。 列表函数用于验证数据。包含 3 个条件的脚本解释如下:
a. 从不同类别中总共只可选择十项
在下面的代码中,If 条件使用 <list>.size() 函数计算每个列表中的项目总数。如果所选的项目总数超过 10,则会显示提醒消息并取消提交。
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. 必须从每个类别中选择至少一项。
在下面的代码中,If 条件使用 <list>.size() 函数检查是否已从每个类别中添加至少一项。如果未添加,则会显示提醒消息并取消提交。
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. 只可包括三个优惠项目。
在以下代码中,
-
- 创建一个名为 totalList 的新列表。
- <list>.addall deluge 任务将给定列表中的元素添加到 totallist。
- Totallist 中的每个元素进行迭代,以便检查已订购的优惠项目的总数。如果优惠项目总数超过 3,则会显示提醒消息并取消提交。
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.“用户输入时”脚本
当您选择/更改表单中的字段值时,执行用户输入时脚本。该脚本计算已选择的项目总数并在 Note 字段中显示。此脚本添加到所有多选列表字段中。
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>";
}
若要安装应用程序,
了解如何将应用程序安装到您的帐户 - 单击此处。