In our Meteor v1.11.1
application, we are using Bootstrap 3, aldeed:autoform@6.3.0
, and aldeed:collection2@3.2.1
in blaze to validate forms. We really want to implement the "least-custom" solution to display and validate our form inputs.
We can't wrap our heads around why even the most basic error message doesn't appear in the form when we submit? We narrowed the form down to one field and a submit. The HTML elements are in the DOM, but no hint of messaging appears upon validation.
The schema for the form is:
Folios = new Mongo.Collection('Folios')
FolioSchema = new SimpleSchema({
"name": {
"type": String,
"min": 2,
"required": true
}
},
{
"requiredByDefault": false,
"clean": {
"filter": true,
"autoconvert": true,
"removeEmptyStrings": true,
"trimStrings": true,
"getAutoValues": true,
"removeNullsFromArrays": true
}
}
Folios.attachSchema(FolioSchema)
The form is:
{{# autoForm id="newFolio"
class="newFolioForm"
collection=getFormCollection
schema=getFormSchema
type=getFormType
validation="submitThenBlur"
resetOnSuccess=true
}}
{{> afQuickField name='name' type='text' }}
<button type="submit">Submit</button>
{{/ autoForm }}
And the helpers for collection
, schema
, and type
are:
Template.newFolioForm.helpers({
getFormCollection()
{
return Folios
},
getFormSchema()
{
return FolioSchema
},
getFormType()
{
return "insert"
}
})
When I click submit, no error message, no error class, nothin'. We've consulted simpl-schema docs. We want to avoid the need to implement afMessage as a part of a fully custom form just to get a message and validation error to display properly.
I thought to check here first. Thank you!
The issue comes from the missing Tracker
that is required in order to generate reactive validation messages:
import { Tracker } from 'meteor/tracker'
FolioSchema = new SimpleSchema({
'name': {
'type': String,
'min': 2,
'required': true
}
},
{
'requiredByDefault': false,
'clean': {
'filter': true,
'autoconvert': true,
'removeEmptyStrings': true,
'trimStrings': true,
'getAutoValues': true,
'removeNullsFromArrays': true
},
tracker: Tracker // this line is important
})
Without passing the Tracker, there is no cause for the template to redraw, since there is no dependency resolved.
Readings: https://github.com/aldeed/simpl-schema#enable-meteor-tracker-reactivity