1
  1. I've added autoform packege (meteor add aldeed:autoform)
  2. I've added collection2-core packege (meteor add collection2-core)
  3. I've installed simpl-schema (npm i --save simpl-schema) But form still does not working correctly

/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>

packages

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

I see the form and it inserts record into database, but validation message not showing and why there is field "created at"? what I'm doing wrong? enter image description here

Roman Yakoviv
  • 1,614
  • 15
  • 19
  • 1
    Can you try doing `AutoForm.debug()` and then resubmitting the form and see if there's an error – Afif Sohaili May 24 '17 at 01:33
  • 1
    What validation message are you expecting it to show? If you submit a blank form, what is getting stored in the DB? Secondly, ```createdAt``` is being shown because it's specified in the schema by you. If you need it to be a hidden field, then use: ```createdAt: { type: Date, autoValue(){ return new Date(); }, autoform: { type: "hidden" } }``` – blueren May 24 '17 at 08:50
  • @blueren thanks for help to figure out with autoValue, I thought it makes field hidden by default – Roman Yakoviv May 24 '17 at 18:05

1 Answers1

4

There is a typo in your Schema, which causes the Tracker not been included. This in the end causes your form to not have (reactive) validation messages. The corrected code is:

Rooms.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: 'Title'
    },
    desc: {
        type: String,
        label: 'Description'
    },
    createdAt: {
        type: Date,
        autoValue(){
            return new Date();
        }
    },
}, {tracker: Tracker}));
Jankapunkt
  • 8,128
  • 4
  • 30
  • 59