2014-04-07 1 views
0

Ui 양식에 비밀번호 생성기 버튼이 있습니다. 생성 된 값을 textBox에 추가하고 싶습니다. 어떤 도움이라도 대단히 감사 할 것입니다.Google Apps Script - UiForm의 텍스트 상자에 값 추가

코드 :

function doGet(e) { 
var app = UiApp.createApplication() 
.setTitle('Password Generator') 
.setHeight(200) 
.setWidth(300); 

var panel = app.createFormPanel(); 
var grid = app.createGrid(4, 3) 
.setId('formGrid'); 

//Password Label and Textbox 
var passLabel = app.createLabel('Password'); // Label Password 
passLabel.setStyleAttributes({fontFamily: "Arial", fontWeight: "bold", color: "#0040FF"}); 

var passTextbox = app.createTextBox() // Text Box Password 
.setId('Password') 
.setWidth('150px') 
.setName('password'); 

가 생성 암호 버튼

var passwordGen = app.createButton("Generate Password") 
.setId("passwordGen"); 
passwordGen.addClickHandler(app.createServerHandler("passGenFunction")); 
app.add(passwordGen); 

grid.setWidget(0, 1, passLabel) 
.setWidget(1, 1, passTextbox) 
.setWidget(1, 2, passwordGen) 

panel.add(grid) 
app.add(panel); 
SpreadsheetApp.getActiveSpreadsheet().show(app); 
} 

비밀 번호 생성기 기능 섹션

function password_generator() { 
var confirm; 
var length = 16; 
var pass = ""; 
var possible = "[email protected]#$%&?"; 

for(var i=0; i < length; i++) 
pass += possible.charAt(Math.floor(Math.random() * possible.length)); 
//Missing code: generator button clicked. Results placed into passTextbox// 
return app; 
} 

답변

0

$textBoxId$pass을 추가하십시오 password_generator 기능에, 하나 개의 라인 :

return UiApp.getActiveApplication().getElementById('Password').setText(pass);

+0

안녕 방탄복은 한 줄의 코드를 주셔서 감사합니다,하지만 때 나는를 넣어 '$ pass + = possible.charAt (Math.random() * possible.length));'와'var app = UiApp.createApplication(); '을 제거한 후에 생성기가 작동하지 않습니다. – WallyG

+0

https://docs.google.com/spreadsheet/ccc?key=0Ag8NytPhOo00dEFjT0JIMDZsTmxlN1JLSFJ0TnJLNUE&usp=sharing – WallyG

0

대답을 나타냈다.

$var app = UiApp.createApplication();$function passGenFunction() 아래에 정의해야했습니다. 그런 다음 대답은 더 간단했다 $app.getElementById("Password").setText(pass);