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

时间:2017-05-23 20:43:48

标签: meteor meteor-autoform simple-schema meteor-collection2

  1. 我添加了autoform packege(meteor add aldeed:autoform)
  2. 我添加了collection2-core packege(meteor add collection2-core)
  3. 我已经安装了simple-schema(npm i --save simpl-schema) 但表格仍然无法正常工作
  4. /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
    

    我看到了表单,它将记录插入到数据库中,但验证消息未显示,为什么有字段&#34;在&#34;?我做错了什么? enter image description here

1 个答案:

答案 0 :(得分:4)

您的架构中存在拼写错误,导致未包含跟踪器。这最终会导致您的表单没有(被动)验证消息。更正的代码是:

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