首页 文章

如何添加时间小部件/选择器?

提问于
浏览
0

这里有新的appmaker用户 .

我正在尝试移植工作许可批准“app”我用G Suite表格电子表格GAS;用户应输入许可证的日期,开始和结束时间 .

我可以从Forum Sample看到Date字段类型是DateTime字段类型,所以我可以在我的模型中使用它 .
问题是我在窗口小部件中找不到时间选择器,并且日期框也没有选项也可以输入时间 .

我错过了什么吗?

3 回答

  • 0

    此时App Maker不提供开箱即用的时间或日期/时间选择器小部件,这意味着您需要自己实现一个 . 至少有两种方法可以完成此任务:

    App Maker way

    等待并希望App Maker将引入时间或日期/时间选择器窗口小部件或使用现有的App Maker窗口小部件来模拟时间选择器 . Calendar Sample可以是一个很好的起点:
    Calendar Sample

    Hack into DOM/JS

    如果您不担心跨浏览器兼容性,并且您可以通过javascript使用DOM操作,创建事件监听器和其他很酷的东西,那么您可以使用HTML widget和本机date/timetime输入,甚至是第三个党的图书馆 .

  • 1

    App Maker的时间选择器

    我读了你的问题,并认为我会尝试自己的角色,这就是我想出的 . 我将所有按钮放在pageFragment上并用 app.showDialog(app.pageFragments.timePicker2); 调用它

    我只使用客户端脚本 .

    function updateOutput(){
      var h=app.pageFragments.TimePicker2.properties.hour||'00';
      var m=app.pageFragments.TimePicker2.properties.minute||'00';
      var s=app.pageFragments.TimePicker2.properties.second||'00';
      var t=h + ':' + m + ':' + s;
      app.pageFragments.TimePicker2.descendants.timeLBL.text=t;
      return t;
    }
    function updateHour(v){
      app.pageFragments.TimePicker2.properties.hour=v;
      updateOutput();
    }
    function updateMinute(v){
      app.pageFragments.TimePicker2.properties.minute=v;
      updateOutput();
    }
    function updateSecond(v){
      app.pageFragments.TimePicker2.properties.second=v;
      updateOutput();
    }
    

    这是我的时间选择器的样子:

    enter image description here

    是 . 添加所有按钮是令人讨厌的,但有 a few features about AppMaker that make it more tolerable.

    首先,您可以指定我用作全局属性的TimePicker表单属性 . 我有三小时,一分钟和一秒钟 .

    然后在添加所有小时按钮后,您可以在按住Windows机器上的控件的同时单击每个小时按钮同时抓取所有小时按钮,然后单击onClick事件并选择自定义操作并在updateHour中键入此内容(widget.text );代码完成不会将文本作为选项提供,但可以任何方式键入 .

    I just figured out how to grab the buttons all a one time by pushing shift and selecting with the mouse

    使用 updateMinute(widget.text)updateSecond(widget.text); This saves you a lot of time typing all of the functions into each widget control panel. 对分钟和秒按钮执行相同的操作 . 此外,您不必费心给出所有按钮特殊名称,就像我一样 .

    但您可能希望使用以下css格式化它们 .

    enter image description here

    您可以同时抓取所有按钮并更改以下设置:

    enter image description here

    这样您就可以同时设置所有按钮的样式 .

    我的保存按钮只是将最终字符串复制到主面板上的标签中 .

    app.pages.Testing.descendants.timeLBL2.text=app.pageFragments.TimePicker2.descendants.timeLBL.text;
    app.closeDialog();
    

    你可能想要做一些更优雅的事情 .

    Here's a demo:处于预览模式 . 抱歉24小时制 . 我总是将它用于我自己的东西,因为它可能需要上午和下午 . 我可能会回去做那件事 .

    对于AM / PM Picker,我使用了以下功能:

    function updateOutputAP(){
      var h=app.pageFragments.TimePicker3.properties.hour||'00';
      var m=app.pageFragments.TimePicker3.properties.minute||'00';
      var s=app.pageFragments.TimePicker3.properties.second||'00';
      var ap=app.pageFragments.TimePicker3.properties.ap||'  ';
      var t=h + ':' + m + ':' + s + ' ' + ap;
      app.pageFragments.TimePicker3.descendants.timeLBL.text=t;
      return t;
    }
    function updateHourPM(v){
      app.pageFragments.TimePicker3.properties.hour=v;
      app.pageFragments.TimePicker3.properties.ap='PM';
      updateOutputAP();
    }
    function updateHourAM(v){
      app.pageFragments.TimePicker3.properties.hour=v;
      app.pageFragments.TimePicker3.properties.ap='AM';
      updateOutputAP();
    }
    function updateMinuteAP(v){
      app.pageFragments.TimePicker3.properties.minute=v;
      updateOutputAP();
    }
    function updateSecondAP(v){
      app.pageFragments.TimePicker3.properties.second=v;
      updateOutputAP();
    }
    

    这就是我的选择器的样子:

    enter image description here

    现在我知道如何使用鼠标轻松选择组件,这是一个休息时间来进行此更改 .

    Three AppMaker Time Pickers:

  • 0

    一个简单的选择是简单地使用文本框并在模型字段中设置验证 . 您可以在保存时更新Date对象,也可以按原样使用,具体取决于您的应用程序 . 您可以在UI中获得自动验证错误的好处,以指导您的用户,并且只需几秒钟即可完成设置 .

    正则表达式:

    \b((1[0-2]|0?[1-9]):([0-5][0-9]) ([AaPp][Mm]))
    

    Model Feild

相关问题