Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

error display error pre-submit autoform #1664

Closed Pierre-Mike closed 6 years ago

Pierre-Mike commented 6 years ago

Thanks for the packages.

I've been looking for a while how to make error messages appear with autoform, autoform debug is enabled, SimpleSchema.debug too

I get all messages well in the console autoform-api.js:734 Error in insertLinks pre-submit validation Error: Title is required

and if I change page and then I return the error fields appear html

        {{#autoForm collection="Links" schema=link  id="insertLinks" type="insert" validation="blur"}}
            {{{afFieldMessage}}}
            {{{afFieldIsInvalid afFieldNames='title'}}}
            {{> afQuickField name="title"}}

            {{> afQuickField name="url"}}
            <input type="submit" value="Enregistrer" class="btn btn-primary">
            {{#if afFieldIsInvalid name='title'}}
                <span class="help-block">{{afFieldMessage name='title'}}</span>
            {{/if}}
        {{/autoForm}}

links.js


// Definition of the links collection
import {Mongo} from 'meteor/mongo'
import {Tracker} from 'meteor/tracker'
import SimpleSchema from 'simpl-schema';

SimpleSchema.debug = true
SimpleSchema.extendOptions(['autoform']);

SimpleSchema.Links = new SimpleSchema({
    _id : {
        type: String,
        regEx: SimpleSchema.RegEx.Id,
        optional:true
    },
    title: {
        type: String,
        label: "Title",
        max: 200,
        optional: false,
    },
    url: {
        type: String,
        label: "Url",
        regEx: SimpleSchema.RegEx.Url,
        optional: false,
    },
    createdAt: {
        type: Date,
        optional: true,
        autoValue : () => new Date(),
    }
});

Links = new Mongo.Collection('links');
Links.attachSchema(SimpleSchema.Links,{ tracker: Tracker });

aldeed:autoform aldeed:collection2@3.0.0

"simpl-schema": "^1.5.0"

Pierre-Mike commented 6 years ago
SimpleSchema.Links = new SimpleSchema({
    _id : {
        type: String,
        regEx: SimpleSchema.RegEx.Id,
        optional:true
    },
    title: {
        type: String,
        label: "Title",
        max: 200,
        optional: false,
    },
    url: {
        type: String,
        label: "Url",
        regEx: SimpleSchema.RegEx.Url,
        optional: false,
    },
    createdAt: {
        type: Date,
        optional: true,
        autoValue : () => new Date(),
    }
},{ tracker: Tracker });

Links = new Mongo.Collection('links');
Links.attachSchema(SimpleSchema.Links);

i'ts better sorry for that !!!