提交后的后处理输入字段

时间:2017-03-22 09:40:25

标签: meteor

我正在使用Meteor构建应用程序。我使用autoform,但我希望在提交后对一些输入字段进行后处理:在转换为字符串时添加前导零(20 - >" 00020"),将货币值更改为整数($ 20 - > ; 2000或$ 21.34 - > 2134)。我不知道该怎么做。任何人都可以帮我吗?我的问题是触发后处理。一些例子会很棒。 此致,Roel

1 个答案:

答案 0 :(得分:0)

在表单中添加一个前挂钩

来自:https://github.com/aldeed/meteor-autoform#callbackshooks

  

在表单被认为有效但之前调用之前的挂钩   提交操作发生了。 (提交操作取决于   表单类型。)这些挂钩作为文档或修饰符传递   从表单字段中收集。如果有必要,他们可以修改   文件或修饰语。

在客户端代码中的某个地方,只会加载一次,添加:

AutoForm.hooks({
  myFormId: {
     before: {
       // Replace `formType` with the form `type` attribute to which this hook applies
       formType: function(doc) {
       // Potentially alter the doc
       doc.foo = 'bar';

       // Then return it or pass it to this.result()
       //return doc; (synchronous)
       //return false; (synchronous, cancel)
       //this.result(doc); (asynchronous)
       //this.result(false); (asynchronous, cancel)
     }
  }      
});
相关问题