Validation Google forms应用程序脚本对现有字段的表单验证

Validation Google forms应用程序脚本对现有字段的表单验证,validation,google-apps-script,google-forms,Validation,Google Apps Script,Google Forms,我正在尝试将验证添加到现有的Google表单中。我已经能够识别要添加验证的字段的项目ID。我只是在我的文本验证中做了第一个非常基本的requireTextContainesPattern。我试着跟着 当我调试代码时,我得到 TypeError: item.setValidation is not a function 我的问题是:1)我如何将这个文本验证输入到我现有的Google表单字段中?2) 我所犯的错误是否与我的第一个问题有关?但首先,我想解决第一个问题。 提前谢谢 Form.getIt

我正在尝试将验证添加到现有的Google表单中。我已经能够识别要添加验证的字段的项目ID。我只是在我的文本验证中做了第一个非常基本的requireTextContainesPattern。我试着跟着

当我调试代码时,我得到

TypeError: item.setValidation is not a function
我的问题是:1)我如何将这个文本验证输入到我现有的Google表单字段中?2) 我所犯的错误是否与我的第一个问题有关?但首先,我想解决第一个问题。 提前谢谢

Form.getItemById(id)
返回
Item
。您需要将引用从
Item
更改为
TextItem
。为此,您可以使用方法
asTextItem()
()

函数验证测试(){
var item=form.getItemById(itemID).asTextItem();
// [...]
}
请注意,如果
itemID
不是文本项的ID,则会引发错误

工具书类

哦,谢谢你。实际上,我一直在将.asTextItem()放在这里:item.setValidation(textValidation);使行为:item.TextItem.setValidation(textValidation);
TypeError: item.setValidation is not a function