Validation Google forms应用程序脚本对现有字段的表单验证
我正在尝试将验证添加到现有的Google表单中。我已经能够识别要添加验证的字段的项目ID。我只是在我的文本验证中做了第一个非常基本的requireTextContainesPattern。我试着跟着 当我调试代码时,我得到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
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,则会引发错误
工具书类
TypeError: item.setValidation is not a function