Adding “password” type to Google Apps Script inputBox

北战南征 提交于 2021-02-19 04:36:05

问题


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).


回答1:


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...
};


来源:https://stackoverflow.com/questions/36225756/adding-password-type-to-google-apps-script-inputbox

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