Search code examples
javascriptajaxgoogle-apps-scriptgoogle-formsgoogle-contacts-api

Google Script - Form - live update for a text field


My client has a huge list of contacts. I created a form with a scrolling list, in order to select a contact. The issue is that the scrolling list is too long. Is there a way (and if so, how?) for my client to start typing the first letters of a contact name, so the 'field area' (or other) fills in automatically the correspondant contact name? Thank you in advance for your help. Kind regards,


Solution

  • You can load the select with this javascript:

    function updateSelect(vA)
    {
      var select = document.getElementById("sel1");//or whatever you select id is
      select.options.length = 0; 
      for(var i=0;i<vA.length;i++)
      {
        select.options[i] = new Option(vA[i],vA[i]);
      }
    }
    

    The html select element:

    <select id="sel1">
          <option value="" selected></option>
       </select>
    

    I often load selects when the page loads with something like this:

    $(function(){
    google.script.run
              .withSuccessHandler(updateSelect)
              .getSelectOptions();//a gs function which passes an array to updateSelect via the success handler
     });
    

    That way I can use a spreadsheet to store the values that I want. In your case you may want to filter them alphabetically perhaps. And you might want to pass the getSelectOptioptions() function or whatever you call it a parameter to determine how to filter the list.