Is there a way to get autocomplete in a ui element in Google Apps Script?

前端 未结 3 1354
感情败类
感情败类 2021-02-06 19:14

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 autocomple

相关标签:
3条回答
  • 2021-02-06 19:44

    [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

    0 讨论(0)
  • 2021-02-06 19:51

    See http://googleappsdeveloper.blogspot.in/2011/05/autocomplete-email-addresses-in-apps.html for an example of autocomplete

    0 讨论(0)
  • 2021-02-06 19:53

    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>
    
    0 讨论(0)
提交回复
热议问题