는, 그들 중 하나는 길이 검증을
var clientHandler = app.createClientHandler().validateLength(widget, min, max)
을 사용하고 setVisible
에 경고 메시지를이 사용하고 결국 '제출'버튼을 '...
을 비활성화하는 것입니다
documentation on clientHandlers 여기
경고 메시지를
question 1
를 확인하고 표시하는 간단한 형태의 예는 매우 명시 적이다 :
,691,363 (210)
function BuildForm() {
var text= new Array();
text =['question 1','question 2','question 3','question 4','question 5','question 6'];
var textBox = new Array();
var app=UiApp.createApplication().setTitle('Form');
var panel = app.createVerticalPanel().setId('panel');
var btn = app.createButton('process');
var warning = app.createLabel('You forgot to fill in question 1').setVisible(false)
for (nn=0;nn<text.length;++nn){
var label = app.createLabel(text[nn]);
textBox[nn] = app.createTextBox().setName(text[nn].replace(' ',''));
panel.add(label).add(textBox[nn])
}
var cliH1 = app.createClientHandler().validateLength(textBox[0], 0, 1)
.forTargets(btn).setEnabled(false)
.forTargets(warning).setVisible(true)
var cliH2 = app.createClientHandler()
.forTargets(btn).setEnabled(true)
.forTargets(warning).setVisible(false)
var servH = app.createServerHandler('process').addCallbackElement(panel).validateLength(textBox[0], 1, 40)
btn.addClickHandler(cliH1)
textBox[0].addClickHandler(cliH2)
btn.addClickHandler(servH)
panel.add(btn).add(warning)
app.add(panel)
var doc = SpreadsheetApp.getActive();
doc.show(app)
}
function process(e){
var app = UiApp.getActiveApplication()
Browser.msgBox(e.parameter.question1+' '+e.parameter.question2+' '+e.parameter.question3+' '+e.parameter.question4+' '+e.parameter.question5+' '+e.parameter.question6)
app.close()
return app
}
편집 : 여기에 또 다른 검증 (validateMatches)를 사용하여 모든 검사를 또 다른 버전이
function BuildForm2() {
var text= new Array();
text =['question 1','question 2','question 3','question 4','question 5','question 6'];
var textBox = new Array();
var app=UiApp.createApplication().setTitle('Form');
var panel = app.createVerticalPanel().setId('panel');
var btn = app.createButton('process').setWidth('240');
var warning = app.createLabel('You forgot to fill at least one question').setVisible(false)
for (nn=0;nn<text.length;++nn){
var label = app.createLabel(text[nn]);
textBox[nn] = app.createTextBox().setName(text[nn].replace(/ /g,''));
panel.add(label).add(textBox[nn])
}
var servH = app.createServerHandler('process').addCallbackElement(panel).validateLength(textBox[0], 1, 40).validateLength(textBox[1], 1, 40).validateLength(textBox[2], 1, 40)
.validateLength(textBox[3], 1, 40).validateLength(textBox[4], 1, 40).validateLength(textBox[5], 1, 40);
var cliH = app.createClientHandler().validateMatches(textBox[0],'').validateMatches(textBox[1],'').validateMatches(textBox[2],'').validateMatches(textBox[3],'')
.validateMatches(textBox[4],'').validateMatches(textBox[5],'')
.forTargets(warning).setVisible(true)
btn.addClickHandler(servH).addClickHandler(cliH)
panel.add(btn).add(warning)
app.add(panel)
var doc = SpreadsheetApp.getActive();
doc.show(app)
}
응답