簡體   English   中英

為什么 Meteor autoForm afQuickField Errors 出錯時不顯示?

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

在我們的 Meteor v1.11.1應用程序中,我們使用 Bootstrap 3、 aldeed:autoform@6.3.0aldeed:collection2@3.2.1來驗證 forms。 我們真的想實現“最少定制”的解決方案來顯示和驗證我們的表單輸入。

我們無法理解為什么在提交時即使是最基本的錯誤消息也不會出現在表單中? 我們將表單縮小到一個字段和一個提交。 HTML 元素在 DOM 中,但在驗證時沒有消息提示出現。

表單的架構是:

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)

表格是:

{{# 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 }}

collectionschematype的助手是:

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

當我單擊提交時,沒有錯誤消息,沒有錯誤 class,沒什么。 我們已經查閱了simpl-schema docs 我們希望避免將afMessage實現為完全自定義表單的一部分,只是為了正確顯示消息和驗證錯誤。

我想先檢查這里。 謝謝!

問題來自生成響應式驗證消息所需的缺少的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
  })

如果不通過 Tracker,模板就不會重繪,因為沒有解決依賴關系。

讀數: https://github.com/aldeed/simpl-schema#enable-meteor-tracker-reactivity

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM