Google Script - Form - live update for a text field

核能气质少年 提交于 2020-12-27 07:13:50

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/46957965/google-script-form-live-update-for-a-text-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!