我查看了Google的产品论坛,我找不到任何东西。帮助文本字段是为简短文本设计的,但我想插入一个多段文章。如果没有分段符号,我最终会收到一堆难以阅读的文字。
答案 0 :(得分:6)
很长一段时间以来,这一直困扰着我,我想出了一个基于Apps Script的不太优雅但有效的解决方案。帕维尔·阿加科夫(Pavel Agarkov)也有同样的想法!我的版本也可以多次出现,并且如果在编辑文本时Google表单删除了换行符,则可以重新运行我的版本。
创建一个新脚本,将内容替换为下面的代码。保存并返回您的表单。
重新加载页面。您会在主菜单中看到一个新选项,如下所示
该“脚本”菜单是我们的脚本添加的。暂时不要使用它,它不会做很多事情。
从“脚本”菜单运行脚本。现在庆祝??️
一些值得注意的事情:
您将在第一次运行脚本时收到许可请求。没关系,请阅读消息并做您必须做的事情。
一旦有换行符,上帝保佑您的Google Forms会在每次编辑该字段时将其删除。轻度令人发指。只需再次运行脚本。
您需要使用的脚本是:
// From https://stackoverflow.com/questions/22207368/
function onOpen() {
var ui = FormApp.getUi();
ui.createMenu('Scripts')
.addItem('Replace 4+ spaces with line breaks in Title and Description', 'addLineBreaks')
.addToUi();
}
function addLineBreaks() {
var theForm = FormApp.getActiveForm();
var theQuestions = theForm.getItems();
var thePlaceholder = new RegExp(/\s{4,99}|\n/, 'gi');
for (i = 0; i < theQuestions.length; i++) {
var theText = theQuestions[i].getHelpText();
if (theText.search(thePlaceholder) > 0 ) {
theQuestions[i].setHelpText(theText.replace(thePlaceholder,' \n'));
}
theText = theQuestions[i].getTitle();
if (theText.search(thePlaceholder) > 0 ) {
theQuestions[i].setTitle(theText.replace(thePlaceholder,' \n'));
}
}
}
答案 1 :(得分:4)
我自己在这个问题上挣扎太久了! 但是,当你知道它的简单之处: 转到“添加项目” 选择“节标题” 此选项允许您将已删除的文本放入表单中。
答案 2 :(得分:4)
我发现你无法通过编辑器完成它,但可以通过脚本实现。 转到主菜单 - &gt;脚本编辑器; 将以下代码发送给编辑器;
function addLineBreaks()
{
var form = FormApp.getActiveForm();
// find form items you need
var questions = form.getItems(FormApp.ItemType.MULTIPLE_CHOICE);
for(i = 0; i < questions.length; i++)
{
var title = questions[i].getTitle();
if(title.indexOf("\n") < 0)
{
// in my case I always need line break before "B:"
// you can replace your special symbol
// for example: "<br>" or "<p>"
questions[i].setTitle(title.replace("B:", "\nB:"));
}
}
}
&#13;
然后设置触发器以在窗体打开时启动此方法。
答案 3 :(得分:0)
抱歉这个坏消息,但这对我来说似乎不可能。
答案 4 :(得分:0)
我找到了答案!在输入文本的框中,转到“开发人员”选项卡中的“属性”。您将看到一个下拉菜单。菜单底部是“普通测试属性”,带有“允许回车(多段)”复选框。
答案 5 :(得分:0)
截至2018年6月,以下工作(但仅记录了第二个选项):
答案 6 :(得分:0)
以上解决方案均不适用于我,因此我添加了粘贴4至5次的Unicode字符https://www.compart.com/en/unicode/U+2002,这就是它的外观
答案 7 :(得分:0)
这是一个更好的解决方案,但基于以上内容。它使您可以编辑上述解决方案无法做到的形式:
// Version 2020-10-07a: by Dennis Bareis
// Handles "{nl}" in form & question descriptions
// Forms API: https://developers.google.com/apps-script/reference/forms
// Based on https://stackoverflow.com/questions/22207368/
// This code @: https://stackoverflow.com/a/64216993/3972414
// [0] ... -> Script Editor -> Create New Script
// [1] Paste into script editor
// [2] Run onOpen()
// [3] On first run authorise script
// [4] This adds 2 scripts under a new button in the edit form UI
// (to the left of the "Send" button)
// [5] Use "START" before re-editing form
// [6] Use "END" to publish the changes
// 5&6 required as otherwise you end up with "line1Line2Line3" etc
String.prototype.replaceAll = function(search, replacement)
{
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
//This doesn't perform the function on open, just adds it to the UI, you run when finished.
function onOpen()
{
var ui = FormApp.getUi();
ui.createMenu('Scripts')
.addItem('[1] Prepare for RE-EDITING this form (restore {nl})', 'editFormStart')
.addItem('[2] Publish the form (finished editing, remove {nl})', 'editFormEnd')
.addToUi();
}
function editFormStart()
{
swapLineBreaks("\n", "{nl}")
}
function editFormEnd()
{
swapLineBreaks("{nl}", "\n")
}
function swapLineBreaks(FromText, ToText)
{
var form = FormApp.getActiveForm();
// find form items you need
var oForm = FormApp.getActiveForm();
var questions = oForm.getItems();
// Fix the form's description
var formDesc = oForm.getDescription()
oForm.setDescription(formDesc.replaceAll(FromText, ToText))
// Work through each question
for(i = 0; i < questions.length; i++)
{
//var QTitle = questions[i].getTitle();
//questions[i].setTitle( QTitle.replaceAll(FromText, ToText));
var QText = questions[i].getHelpText();
questions[i].setHelpText(QText.replaceAll(FromText, ToText));
}
}