根据prev的数据动态地在表单中创建一个新页面。页 [英] create a new page in a form dynamically, based on data of the prev. page

查看:96
本文介绍了根据prev的数据动态地在表单中创建一个新页面。页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于Google-apps-script中的表单的问题。比方说,我已经创建了一个单一页面和文本输入框的表单。
是否可以根据文本框中的数据动态创建后续页面?例如:

首页:插入客户ID - >继续 - >第二页:有关客户的信息。



我知道有像onLoad和onSubmit这样的事件,但没有onContinue事件。

是否可以使用google-apps-script创建类似的内容?什么是归档这种行为的最佳方式?
BR

解决方案使用 UiApp 一个 doGet()和一个 doPost()函数...但是这里有一种方法来扩展它们以支持动态多部分形式。 (示例代码来自此答案



您的 doGet()只需构建表单的第一部分,然而在表单中,您需要按名称标识表单,如下所示:

  var form = app.createFormPanel()。setId(emailCopyForm); 

然后,您将 doPost()传递到不同的函数,取决于(还包括: reportFormParameters(),这是一个默认的处理程序,它将显示由表单部件收集的所有数据。)

  / ** 
*具有多表单处理功能的doPost函数个别表单处理程序必须
*返回UiApp实例
* /
函数doPost(eventInfo){
var app;
Logger.log(Form ID =%s,eventInfo.parameter.formId);
//为发布表单
swit调用适当的处理程序ch(eventInfo.parameter.formId){
case'emailCopyForm':
app = postEmailCopyForm(eventInfo);
休息;
默认值:
app = reportFormParameters(eventInfo);
休息;
}
返回应用;
}

/ **
*调试函数 - 返回包含
*提供的表单事件中的所有参数的UiInstance。
*
*使用示例:
*< pre>
* function doPost(eventInfo){
* return reportFormParameters(eventInfo);
*}
*< / pre>
*
* @param {Event}来自UiApp的eventInfo事​​件表单提交
*
* @return {UiInstance}
* /
函数reportFormParameters(eventInfo ){
var app = UiApp.getActiveApplication();
var panel = app.createVerticalPanel();
panel.add(app.createLabel(Form submitted));
for(var inparameter in eventInfo.parameter){
switch(param){
//跳过噪音;这些密钥由UiApp内部使用
case'lib':
case'appId':
case'formId':
case'token':
case'csid ':
case'mid':
break;

//以
形式命名的报表参数默认值:
panel.add(app.createLabel( - + param +=+ eventInfo.parameter [param]) );
休息;
}
}
app.add(panel);
返回应用程序;
}

为了生成每个表单部分,后续的表单处理程序可以使用之前检索的数据部分动态添加新的Form对象到UI。


I have a question regarding forms in google-apps-script. Lets say I have already created a form with a single page and a input box for text. Is it possible to create the follow-up page dynamically, based on the data out of the textbox? Something like:

First Page: insert customer id -> continue -> Second Page: information about the customer.

I know that there are events like onLoad and onSubmit, but there is no onContinue event for example.

Is it possible to create something like that with google-apps-script? What would be the best way to archive such a behavior? B.R.

解决方案

Using the UiApp service, you have one doGet() and one doPost() function... but here's a way to extend them to support a dynamic multi-part form. (The example code is borrowed from this answer.

Your doGet() simply builds part1 of your form. In the form, however, you need to identify your form by name, like this:

  var form = app.createFormPanel().setId("emailCopyForm");

You doPost() then, will pass off handling of the post operation to different functions, depending on which form has been submitted. See below. (Also included: reportFormParameters (), a default handler that will display all data collected by a form part.)

/**
 * doPost function with multi-form handling. Individual form handlers must
 * return UiApp instances.
 */
function doPost(eventInfo) {
  var app;
  Logger.log("Form ID = %s", eventInfo.parameter.formId);
  // Call appropriate handler for the posted form
  switch (eventInfo.parameter.formId) {
    case 'emailCopyForm':
      app = postEmailCopyForm(eventInfo);
      break;
    default:
      app = reportFormParameters (eventInfo);
      break;
  }
  return app;
}

/**
 * Debug function - returns a UiInstance containing all parameters from the
 * provided form Event.
 *
 * Example of use:
 * <pre>
 *     function doPost(eventInfo) {
 *       return reportFormParameters(eventInfo);
 *     }
 * </pre>
 *
 * @param {Event} eventInfo Event from UiApp Form submission
 *
 * @return {UiInstance}
 */
function reportFormParameters (eventInfo) {
  var app = UiApp.getActiveApplication();
  var panel = app.createVerticalPanel();
  panel.add(app.createLabel("Form submitted"));
  for (var param in eventInfo.parameter) {
    switch (param) {
      // Skip the noise; these keys are used internally by UiApp
      case 'lib':
      case 'appId':
      case 'formId':
      case 'token':
      case 'csid':
      case 'mid':
        break;

      // Report parameters named in form
      default:
        panel.add(app.createLabel(" - " + param + " = " + eventInfo.parameter[param]));
        break;
    }
  }
  app.add(panel);
  return app;
}

To generate each form part, subsequent form handlers can use the data retrieved in previous parts to dynamically add new Form objects to the ui.

这篇关于根据prev的数据动态地在表单中创建一个新页面。页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆