简体   繁体   中英

Adding “password” type to Google Apps Script inputBox

Is it possible to assign the "password" type to the Google Apps Script inputBox so the text doesn't show?

The following is working just fine, but the input field is a simple textbox and displays the text rather than "••••••••":

Browser.inputBox('Please enter your password');

I have a Google Sheet with an associated script that automatically populates some cells with information retrieved from an external API. The API requires simple authentication so that's why I'm prompting the user for their username and password (this is for an internal tool so there are no issues with asking for the password, it's not being stored or anything).

Per Sandy Good's comment, I ended up using a custom dialog with an HTML service .

The following works great to show the input with type "password" and pass the value to my google script:

pw_input.html

<script>
  function updateInfo(form) {
    google.script.run.myOtherScript(form.password.value);
    google.script.host.close();
  }
</script>
<form>
  Password:
  <input type="password" name="password">
  <input type="button" value="OK" onclick="updateInfo(this.form)" />
</form>

main.gs

function myMainFunc() {

  onOpen();

  var html = HtmlService.createHtmlOutputFromFile('pw_input')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi()
      .showModalDialog(html, 'Please enter your password');
};

other_script.gs

function myOtherScript(promptResponse) {
  etc...
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM