流星 1.4。不显示 AutoForm 验证消息

Meteor 1.4. AutoForm validation message not showing

  1. 我已经添加了 autoform packege(流星添加 aldeed:autoform)
  2. 我添加了 collection2-core packege(流星添加 collection2-core)
  3. 我已经安装了 simpl-schema (npm i --save simpl-schema) 但是表格仍然无法正常工作

/imports/api/rooms/rooms.js

import { Tracker } from 'meteor/tracker';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);

export const Rooms = new Mongo.Collection('rooms');

Rooms.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: 'Title'
    },
    desc: {
        type: String,
        label: 'Description'
    },
    createdAt: {
        type: Date,
        autoValue(){
            return new Date();
        }
    },
}), {tracker: Tracker});

/imports/ui/pages/home.js

import { Template } from 'meteor/templating';

import './home.html';

import { Rooms } from '../../api/rooms/rooms.js'

Template.Home.helpers({
    rooms() {
        return Rooms.find({});
    },
    CollectionRooms() {
        return Rooms;
    }
});

/imports/ui/pages/home.html

<template name="Home">
    <div class="jumbotron">
        <div class="container text-center">
            <h1>Forum</h1>
            <p>“Don't raise your voice, improve your argument."</p>
        </div>
    </div>

    <div class="container-fluid bg-3">
        <h3 class="page-header">Choose your room</h3>

        {{> quickForm collection=CollectionRooms id="insertRoomsForm" type="insert"}}

        <div class="row grid-divider">
        {{#each rooms}}
            <div class="col-sm-4">
                <div class="col-padding">
                    <h3>{{title}}</h3>
                    <p>{{desc}}</p>
                </div>
            </div>
        {{/each}}
        </div>
    </div>
</template>

meteor-base@1.0.4             # Packages every Meteor app needs to have
mobile-experience@1.0.4       # Packages for a great mobile UX
mongo@1.1.17                   # The database Meteor supports right now
blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
reactive-var@1.0.11            # Reactive variable for tracker
tracker@1.1.3                 # Meteor's client-side reactive programming library

standard-minifier-css@1.3.4   # CSS minifier run for production mode
standard-minifier-js@2.0.0    # JS minifier run for production mode
es5-shim@4.6.15                # ECMAScript 5 compatibility for older browsers.
ecmascript@0.7.3              # Enable ECMAScript2015+ syntax in app code
shell-server@0.2.3            # Server-side component of the `meteor shell` command

autopublish@1.0.7             # Publish all data to the clients (for prototyping)
insecure@1.0.7                # Allow all DB writes from clients (for prototyping)
twbs:bootstrap
iron:router
aldeed:autoform
aldeed:collection2-core

我看到表单并将记录插入数据库,但未显示验证消息,为什么有字段 "created at"?我做错了什么?

您的 Schema 中存在拼写错误,导致未包含 Tracker。这最终会导致您的表单没有(反应性)验证消息。更正后的代码是:

Rooms.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: 'Title'
    },
    desc: {
        type: String,
        label: 'Description'
    },
    createdAt: {
        type: Date,
        autoValue(){
            return new Date();
        }
    },
}, {tracker: Tracker}));