简体   繁体   English

将“密码”类型添加到Google Apps脚本inputBox

[英]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? 是否可以将“密码”类型分配给Google Apps脚本inputBox,以便文本不显示?

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. 我有一个带有关联脚本的Google表格,该脚本会自动使用从外部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). API需要简单的身份验证,这就是为什么我提示用户输入他们的用户名和密码(这是一个内部工具,所以没有问题要求密码,它没有存储或任何东西)。

Per Sandy Good's comment, I ended up using a custom dialog with an HTML service . Per Sandy Good的评论,我最终使用了一个HTML服务自定义对话框

The following works great to show the input with type "password" and pass the value to my google script: 以下工作非常适合显示类型为“password”的输入并将值传递给我的google脚本:

pw_input.html 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 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 other_script.gs

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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