每次提交表单时,我都会使用google脚本向表单中的复选框项添加新的选项。一些现有的复选框项具有附加的图像,用户在填写表单时会看到这些图像。
我的问题是,每次运行我的脚本时,它都会从复选框项中删除图像。有没有一种方法可以在向表单添加新选项的同时保留附加的图像?
(部分)我的代码:
// retrieve form-checkbox object
var item = form.getItems(FormApp.ItemType.CHECKBOX)
.filter(function(item){
return item.getTitle() === 'Top 5 films';
})[0].asCheckboxItem();
//make 2 lists, 'choices' with all choices in the checkbox obj
// 'existingChoicesTitles' with all the titles of the choices.
var choices = item.getChoices();
var existingChoicesTitles = choices.map(function(value){
return value.getValue();
})
//check if obj in list 'values' already exists in array 'choices, if not add to
//'choices'
for (i = 0; i < values.length; i++) {
if (existingChoicesTitles.includes(values[i]) == false){
choices.push(item.createChoice(values[i]));
}
}
//set 'choices' list as new list of choices
item.setChoices(choices);发布于 2021-04-13 16:22:16
不幸的是,目前还没有办法做到这一点。
有一个活跃的功能请求,要求能够使用应用程序脚本FormApp添加这些类型的图像。
我建议你去标记这个问题上的☆,让谷歌知道你想要这个功能,并订阅更新。你可能还想在评论中加入你的经验和用例。
在你的例子中,似乎要向复选框列表添加一个项目,应用程序脚本会重新生成所有的复选框项目,由于FormApp不支持这些类型的图像,因此在重新生成它们时不会包含它们。
对于你的用例来说,除了简单地不以这种方式使用图片之外,似乎没有一个实际的解决办法,如果它们是用Apps脚本修改的话。
如果您愿意投入一些额外的工作,您可能希望将表单实现为一个简单的web app。然后你将拥有几乎无限的灵活性和更多的功能。
Web应用示例
这是一个非常简单的Web应用程序示例,其中显示了一个输入框和一个按钮,用于将信息发送到“后端”,在此示例中为Code.gs
Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile("index")
}
function receiveInfo(formResponse) {
Logger.log(formResponse)
}index.html
<!DOCTYPE html>
<html>
<body>
<input type='text' id='input'></input>
<button id=main>Send Info</button>
<script>
function main(){
const input = document.getElementById('input')
const info = input.value
google.script.run.receiveInfo(info)
}
const mainButton = document.getElementById("main")
mainButton.addEventListener('click', () => main())
</script>
</body>
</html>参考文献
https://stackoverflow.com/questions/67066226
复制相似问题