Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 防止启动服务器处理程序_Google Apps Script - Fatal编程技术网

Google apps script 防止启动服务器处理程序

Google apps script 防止启动服务器处理程序,google-apps-script,Google Apps Script,如果客户端处理程序(在同一个小部件上)满足验证条件,我们可以阻止服务器处理程序启动吗 如果文本框为空,我不希望Submit执行任何服务器功能 function doGet() { var app = UiApp.createApplication(); var flex = app.createFlexTable() .setWidget(0, 0, app.createTextBox().setId('textbox')) .setWidget(0, 1, app.

如果客户端处理程序(在同一个小部件上)满足验证条件,我们可以阻止服务器处理程序启动吗

如果文本框为空,我不希望Submit执行任何服务器功能

function doGet() {
  var app = UiApp.createApplication();
  var flex = app.createFlexTable()
     .setWidget(0, 0, app.createTextBox().setId('textbox'))
     .setWidget(0, 1, app.createButton('Submit').setId('submit'))
     .setWidget(0, 2, app.createLabel().setId('status'));

  var clientHandler = app.createClientHandler().validateNotMatches(app.getElementById('textbox'), ' ');

  var serverHandler = app.createServerHandler('submit').addCallbackElement(flex);

  app.getElementById('submit').addClickHandler(clientHandler).addClickHandler(serverHandler);

  app.add(flex);
  return app;

}

function submit(e) {
  var app = UiApp.getActiveApplication();
  app.getElementById('status').setText('Server handler fired');
  return app;
}

这里不需要或不需要客户端处理程序,只需要服务器处理程序上的验证程序:

function doGet() {
  var app = UiApp.createApplication();
  var flex = app.createFlexTable()
     .setWidget(0, 0, app.createTextBox().setId('textbox'))
     .setWidget(0, 1, app.createButton('Submit').setId('submit'))
     .setWidget(0, 2, app.createLabel().setId('status'));

  var serverHandler = app.createServerHandler('submit')
     .validateLength(app.getElementById('textbox'), 1, null)
     .addCallbackElement(flex);

  app.getElementById('submit').addClickHandler(serverHandler);

  app.add(flex);
  return app;

}

function submit(e) {
  var app = UiApp.getActiveApplication();
  app.getElementById('status').setText('Server handler fired');
  return app;
}
如果您想要一条消息来解释出错的原因,可以添加以下内容:

var clientHandler = app.createClientHandler()
    .validateNotLength(app.getElementById('textbox'), 1, null)
    .forTargets(app.getElementById('status'))
    .setText('Cannot be empty');

app.getElementById('submit').addClickHandler(serverHandler)
    .addClickHandler(clientHandler);

我怎么能在“状态”标签上加一个setText()来表示“文本框不能为空”?