Search code examples
google-apps-scriptgoogle-forms

Create tabulation in answer text field?


Is it possible to create an index key for a Paragraph answer field?

For example:

Google Form Question: Name of cities:

|----------------------------------|
|1.                                |
|2.                                |
|3.                                |
|----------------------------------|

So it automatically fills "1." then when I press enter, fills with "2." and so on.


Solution

  • It is not possible exactly the way you described, but there are two things you can do:

    1. Create a form with pre-filled responses

    enter image description here

    enter image description here

    Programmatically you can achieve this functionality with the methods withItemResponse() and toPrefilledUrl():

    function prefillParagraphResponse(){
      var form = FormApp.getActiveForm(); 
      var items = form.getItems();
      var paragraphItem;
      for(var i in items){
        if(items[i].getTitle()=="Google Form Question: Name of cities"){
          paragraphItem=items[i];
          }
       }   
      Logger.log(form.createResponse().withItemResponse(paragraphItem.asParagraphTextItem().createResponse("1. \n2. \n3.")).toPrefilledUrl());
    }
    
    1. Split the question in several questions

    enter image description here

    This has the advantage of all answers being stored as a separate entry of the array itemResponses, and you can programmatically assign a different index key to each one and access them selectively - if this is your purpose.