【发布时间】:2015-12-18 19:03:54
【问题描述】:
下面是我的嵌套架构。 name.first 是必需的。但是当我提交它没有验证的表单时,它允许空字符串。我错过了什么吗?或者如何解决这个问题?
Schema.UserProfile = new SimpleSchema({
'name.first': {
type: String,
max: 50,
label: "First name"
},
'name.last': {
type: String,
optional: true,
max: 50,
label: "Last name"
}
});
Schema.User = new SimpleSchema({
profile: {
type: Schema.UserProfile,
optional: true
},
});
Meteor.users.attachSchema(Schema.User);
表格:
{{#autoForm id="profile" type="method-update" meteormethod="updateProfile" schema=userSchema doc=currentUser collection=Users}}
{{> afQuickField name="profile.name.first" autofocus='' formgroup-class="col-xs-6"}}
{{> afQuickField name="profile.name.last" formgroup-class="col-xs-6"}}
{{/autoForm}}
【问题讨论】:
-
您的架构和表单看起来正确。我将它复制/粘贴到一个小项目中,它按预期工作。清除名字字段会显示消息“需要名字”。 profile.name.first 字段是否真的为空,您是否在 mongoDB 中检查它?你有一个模板助手
Users,它返回 Meteor.users 对吗? -
谢谢@JosHarink。我在
Userstemplatehelper 中犯了一个错误。非常感谢 -
@JosHarink 您是否尝试过在不输入任何数据的情况下提交?
-
不,我坚持你的问题,检查了架构是否经过验证,仅此而已。我做了一个假的
updateProfile方法。为什么?