将quickForm与集合和单独的架构同时使用似乎不起作用

Using quickForm with a collection and separate schema at the same time does not seem to work

本文关键字:不起作用 quickForm 集合 单独      更新时间:2023-09-26

我想在DB中存储一个以秒为单位的时间值。

在表单中,用户应该能够将其键入为字符串(MM:SS)。提交后,字符串(MM:SS)应转换为秒。这就是为什么表单验证所依据的模式与后端用于验证的模式不同(就在将其写入数据库之前)。

所以我做了这里应该做的事(https://github.com/aldeed/meteor-autoform#autoform-1) 我定义了两个模式,一个用于表单(time.type="String"),另一个附加到集合(time.ttype=Number)。

在模板中,我设置了两个参数,collection="TimeItem"schema="SpecialFormSchema

最后,表单始终使用HTML数字输入字段进行渲染,并忽略表单架构

有人能帮忙吗?提前感谢!

集合和架构不支持在一起。你必须选择其中一个。

试着用钩子做你想做的事:https://github.com/aldeed/meteor-autoform#callbackshooks

它实际上可以正常工作。我愚蠢的错误是用不同的模板进行实验,并使用了错误的模板,因此没有看到任何结果。

工作javascript:

// schema for collection
var schema = {
    time: {
        label: "Time (MM:SS)",
        type: Number // !!!
    },
    // ...
};
SongsSchema = new SimpleSchema(schema);
Songs.attachSchema(SongsSchema);
// schema for form validation
schema.time.type = String // changing from Number to String!
SongsSchemaForm = new SimpleSchema(schema);

模板的样子:

{{>quickForm
   id="..."
   type="insert"
   collection="Songs"
   schema="SongsSchemaForm"
}}