【问题标题】:Why won't Meteor autoForm afQuickField Errors display on error?为什么 Meteor autoForm afQuickField 错误不会显示错误?
【发布时间】:2021-03-16 06:09:30
【问题描述】:

在我们的 Meteor v1.11.1 应用程序中,我们在 blaze 中使用 Bootstrap 3、aldeed:autoform@6.3.0aldeed:collection2@3.2.1 来验证表单。我们真的很想实现“最少定制”的解决方案来显示和验证我们的表单输入。

我们无法理解为什么在提交时连最基本的错误消息都没有出现在表单中?我们将表单缩小到一个字段和一个提交。 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"
  }
})

当我点击提交时,没有错误消息,没有错误类,什么都没有。我们咨询了simpl-schema docs。我们希望避免将 afMessage 实现为完全自定义表单的一部分,只是为了让消息和验证错误正确显示。

我想先检查这里。谢谢!

【问题讨论】:

    标签: javascript meteor meteor-blaze


    【解决方案1】:

    问题来自缺少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

    【讨论】:

    • 我忽略了这个细节!你可以挑战 Meteor 的工作吗?
    • 不客气。让我们在 StackOverflow 上的 Meteor 聊天室中进一步讨论:chat.stackoverflow.com/rooms/225553/meteor-talk
    • 刚刚做了。联系我,如果一切顺利,我们就可以开始了。
    猜你喜欢
    • 2016-08-14
    • 2015-07-05
    • 2010-10-08
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 2014-01-03
    相关资源
    最近更新 更多