我在autoform中使用了下面的模式但是我的表单没有显示并返回错误。如何根据模式修复我的表单,以便在meteor-autoform中使用一个表单创建用户和配置文件。
我创建了一个基于this example的模式。
架构:
UserProfile = new SimpleSchema({
name: {
type: String,
label: "Name"
},
family: {
type: String,
label: "Family"
},
address: {
type: String,
label: "Address",
optional: true,
max: 1000
},
workAddress: {
type: String,
label: "WorkAddress",
optional: true,
max: 1000
},
phoneNumber: {
type: Number,
label: "Phone Number",
optional: true
},
mobileNumber: {
type: Number,
label: "Phone Number"
},
birthday: {
type: Date,
optional: true
},
gender: {
type: String,
allowedValues: ['Male', 'Female'],
optional: true
},
description: {
type: String,
label: "Description",
optional: true,
max: 1000
}
});
User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
emails: {
type: [Object],
// this must be optional if you also use other login services like facebook,
// but if you use only accounts-password, then it can be required
optional: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date,
optional: true
},
profile: {
type: UserProfile,
optional: true
},
// // Add `roles` to your schema if you use the meteor-roles package.
// // Option 1: Object type
// // If you specify that type as Object, you must also specify the
// // `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
// // Example:
// // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
// // You can't mix and match adding with and without a group since
// // you will fail validation in some cases.
// roles: {
// type: Object,
// optional: true,
// blackbox: true
// }
// // Option 2: [String] type
// // If you are sure you will never need to use role groups, then
// // you can specify [String] as the type
roles: {
type: [String],
optional: true
}
});
这也是我的autoform代码:
<template name="addUser">
{{#autoForm schema=User type="method" meteormethod="addUser" id="addUserForm"}}
<fieldset>
<legend>add user</legend>
{{> afQuickField name='username'}}
{{> afQuickField name='emails[0].address'}}
{{> afQuickField name='profile.name'}}
{{> afQuickField name='profile.family'}}
{{> afQuickField name='profile.address'}}
{{> afQuickField name='profile.workAddress'}}
{{> afQuickField name='profile.phoneNumber'}}
{{> afQuickField name='profile.mobileNumber'}}
{{> afQuickField name='profile.birthday'}}
{{> afQuickField name='profile.gender'}}
{{> afQuickField name='profile.description'}}
{{> afQuickField name='roles' type="select" options=rolesTypeOptions}}
</fieldset>
<button type="submit" class="btn btn-primary">register</button>
{{/autoForm}}
</template>
如何修复表单以在一个表单中创建具有某个配置文件字段的用户?
感谢您的关注。
答案 0 :(得分:0)
使用 Autoform schema
选项时,您需要确保在范围中定义了您引用的架构。您的架构未显示的原因可能是您没有为User
架构注册帮助程序。尝试将以下行放在您粘贴的架构定义下:
if (Meteor.isClient) {
Template.registerHelper('User', User)
}
此外,良好的反应是启用 Autoform &amp;在开发您的应用时, SimpleSchema 调试模式&amp;形式:
if (Meteor.isClient)
AutoForm.debug()
SimpleSchema.debug = true
在任何development.js文件中,您可能需要在应用中定义开发环境。