问题
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