简体   繁体   English

为什么 Meteor autoForm afQuickField Errors 出错时不显示?

[英]Why won't Meteor autoForm afQuickField Errors display on error?

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.在我们的 Meteor v1.11.1应用程序中,我们使用 Bootstrap 3、 aldeed:autoform@6.3.0aldeed:collection2@3.2.1来验证 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. HTML 元素在 DOM 中,但在验证时没有消息提示出现。

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:collectionschematype的助手是:

Template.newFolioForm.helpers({
  getFormCollection()
  {
    return Folios
  },
  getFormSchema()
  {
    return FolioSchema
  },
  getFormType()
  {
    return "insert"
  }
})

When I click submit, no error message, no error class, nothin'.当我单击提交时,没有错误消息,没有错误 class,没什么。 We've consulted simpl-schema docs .我们已经查阅了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.我们希望避免将afMessage实现为完全自定义表单的一部分,只是为了正确显示消息和验证错误。

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:问题来自生成响应式验证消息所需的缺少的Tracker

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.如果不通过 Tracker,模板就不会重绘,因为没有解决依赖关系。

Readings: https://github.com/aldeed/simpl-schema#enable-meteor-tracker-reactivity读数: https://github.com/aldeed/simpl-schema#enable-meteor-tracker-reactivity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM