Is there a way to get autocomplete in a ui element

2019-03-17 01:25发布

I'd like to have a Listbox or similar, where the user could start typing, and the Listbox would narrow down the choices depending on what has already been typed, and autocomplete once a unique option had been reached

3条回答
爱情/是我丢掉的垃圾
3楼-- · 2019-03-17 02:11

It's fairly easy in HtmlService and a bit harder in UiApp although doable. Here's an HtmlService example:

Code File

function getGroup(group) {
  return GroupsApp.getGroupByEmail(group).getUsers().map(
    function(user){return user.getEmail(); });
}

function doGet() {
  return HtmlService.createHtmlOutputFromFile("ui");
}

Html file named 'ui'

<html>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
  <script>
    function refresh() {
      google.script.run.withSuccessHandler(function(tags) {$( "#tags" ).autocomplete({source: tags});})
        .getGroup(document.getElementById('group').value);
    }
  </script>

  Enter a group name in the first box. The second box will autocomplete
  group members using GroupApp.
  <br>
  <label for="group">Group: </label>
  <input id="group" onchange='refresh()'>
  <div class="ui-widget">
    <label for="tags">Members: </label>
    <input id="tags">
  </div>
</html>
查看更多
唯我独甜
4楼-- · 2019-03-17 02:26

[Edit] HtmlService is faster and more advanced. UiApp works, but is slow because of the network.

The HtmlService solution here Populate jQuery autocomplete list using value array from Google Spreadsheet is much better.

A UiApp version: https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-code-snippets/suggest-box

Or this way that I built:

To see it in action, type an airport name into: http://www.treesforlife.org.au/carbon-calculator

But this was is done with spreadsheet formulas, not google-apps-script. see http://www.cellmaster.com.au

查看更多
登录 后发表回答