1

我有一个简单的 GAS 表格,我希望它对移动设备友好。这是它的样子:

https://script.google.com/macros/s/AKfycbxn6ZasFshHZ6AR0TQzPCv0CUtVNBVbWLSwt1fbOtnc/dev

Q1- 我希望表单自动缩放以适应(移动)屏幕。它是使用 GUI 编辑器构建的。文本框设置为宽度和高度的百分比。

我不知道 HTML5,但这似乎是移动格式化的方式。您可以将 HTML5 集成到 GUI 编辑器使用的代码中吗?您在 GUI 编辑器中还有其他格式建议吗?

Q2 - 我不希望将文本放在文本框中,而是希望它是在选中框时消失的占位符文本。这可能吗?

谢谢,内森

4

2 回答 2

2

For the textholder thing, it is possible to do it without serverhandler, by using validator.

  var textbox = app.createTextBox().setValue('placeholder').setStyleAttribute('color', 'gray');
  textbox.addFocusHandler(app.createClientHandler().validateMatches(textbox, '^placeholder$').forEventSource().setText('').setStyleAttribute('color','black'));
  textbox.addBlurHandler(app.createClientHandler().validateLength(textbox, 0, 0).forEventSource().setText('placeholder').setStyleAttribute('color','gray'));
于 2013-09-20T21:32:32.147 回答
2

Q1:我不能完全回答,但看起来您可以使用 、 或 将大多数元素设置为百分比宽度setWidthsetHeight高度setSize

Q2:您要做的是设置一个 onFocus 处理程序,以便在用户单击该字段时文本消失(此操作称为“聚焦”元素)。这可以通过 ClientHandler 完成,这意味着它会很快。

var text = app.createTextBox().setId("textbox").setName("textbox")
    .setStyleAttribute("color","gray").setValue("Input text here");
var focusHandler = app.createClientHandler().forEventSource().setText("")
    .setStyleAttribute("color","black");
text.addFocusHandler(focusHandler);

如果用户将该字段留空,您可以将其更改回原始文本并再次将其着色为灰色,但这次您必须使用 ServerHandler,因为我们需要检查该字段是否为空白。此外,离开现场被称为“模糊”。

var blurHandler = app.createServerHandler("textboxBlurred").addCallbackElement(text);
text.addBlurHandler(blurHandler);
...
function textboxBlurred(e) {
  var app = UiApp.getActiveApplication();
  if (e.parameter.textbox=="") {
    var box = app.getElementById("textbox");
    box.setValue("Input text here");
    box.setStyleAttribute("color", "gray");
  }
  return app;
}
于 2013-02-11T01:29:45.110 回答