Meteor 使用autoform创建用户注册表单
我在autoform中使用了下面的模式,但我的表单未显示,返回错误。如何基于模式修复我的表单,在meteor autoform中使用一个表单创建用户和配置文件 我创建了一个基于的模式 模式:Meteor 使用autoform创建用户注册表单,meteor,meteor-blaze,meteor-accounts,meteor-autoform,meteor-helper,Meteor,Meteor Blaze,Meteor Accounts,Meteor Autoform,Meteor Helper,我在autoform中使用了下面的模式,但我的表单未显示,返回错误。如何基于模式修复我的表单,在meteor autoform中使用一个表单创建用户和配置文件 我创建了一个基于的模式 模式: UserProfile = new SimpleSchema({ name: { type: String, label: "Name" }, family: { type: String, label: "Family
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
}
});
这也是我的自动表单代码:
<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>
{{{#autoForm schema=User type=“method”meteomethod=“addUser”id=“addUserForm”}
添加用户
{{>afQuickField name='username'}
{{>afQuickField name='emails[0]。地址'}}
{{>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}
登记
{{/autoForm}
如何修复我的表单以在一个表单中创建具有某些配置文件字段的用户
感谢您的关注。当使用自动形成
模式
选项时,您需要确保所引用的模式在范围中定义。未显示模式的原因可能是您没有为用户注册帮助程序。尝试在粘贴的架构定义下放置以下行:
if (Meteor.isClient) {
Template.registerHelper('User', User)
}
另外,开发应用程序和表单时,一个很好的反射就是启用自动表单&SimpleSchema调试模式:
if (Meteor.isClient)
AutoForm.debug()
SimpleSchema.debug = true
在任何development.js文件中,您可能必须在应用程序中定义您的开发环境。您遇到了什么错误?你能分享一下吗。。