Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a paragraph break in Google Form help text?

Tags:

google-forms

I've looked on Google's product forums, and I can't find anything. The help text field is designed for brief text, but I want to insert a mulit-paragraph article. Without paragraph breaks, I wind up with a bunch of text that's difficult to read.

like image 373
user2135450 Avatar asked Mar 05 '14 19:03

user2135450


People also ask

How do you make a new paragraph in Google Forms?

To add a line break in lengthy questions, just hit enter. It will also offer the option of changing text to bold, italic or underline. Further, you can embed a link into a text too.

How do I create a multiline question in Google Forms?

Adding More Questions Click Add Item button below the last question, or Click Insert in the top menu bar. Select one of the following items: Text, Paragraph Text, Multiple Choice, Checkboxes, Choose From a list, Scale, Grid, Date, and Time. Type answer choices if.


2 Answers

This has been bugging me for a long time and I've came up with a not so elegant but efficient solution based on Apps Script. Pavel Agarkov had the same idea! My version also works with multiple occurences and can be re-run if Google Forms removes the line breaks when you edit the text.


  1. When editing a form, open the Script Editor from the main menu. Access the Script Editor menu

  2. Create a new script, replace the content with the code below. Save it and return to your form.

  3. Reload the page. You will notice a new option in the main menu, looking like this
    Scripts menu
    That "Scripts" menu was added by our script. Don't use it for now, it won't do much.

  4. When editing content, use fours spaces as a placeholder for line breaks. Four spaces

  5. Run the script from the Scripts menu. Now celebrate 👯‍♀️

Some things worth noting:

  • You will get a permission request the first time you run the script. It's ok, read the message and do what you have to do.

  • Once the line breaks are there, Google Forms, god bless its heart, will remove them every time you edit the field. Mildly infuriating. Just run the script again.


The script you need to use is:


// 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'));
    }
  }
}
like image 167
Gabriel R. Avatar answered Oct 03 '22 02:10

Gabriel R.


I found that you can't do it through the editor but it is possible via the script. Go to main menu -> script editor; past the following code to the editor;

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 no replacement has been done yet
    if(title.indexOf("\n") < 0)
    {
      // this will add line break after <double space> like in markdown
      questions[i].setTitle(title.replace("  ", "  \n"));
    }
  }
}

then set up trigger to start this method on form open.

like image 22
Pavel Agarkov Avatar answered Oct 03 '22 00:10

Pavel Agarkov