首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用autoform创建用户注册表单

使用autoform创建用户注册表单
EN

Stack Overflow用户
提问于 2015-07-25 23:00:11
回答 1查看 599关注 0票数 2

我在autoform中使用了下面的模式,但我的表单没有显示并返回错误。如何根据模式修复我的表单,以便在meteor-autoform中用一个表单创建用户和配置文件。

我被创建了一个基于this example的模式。

模式:

代码语言:javascript
复制
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
    }
});

这也是我的自动表单代码:

代码语言:javascript
复制
<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>

如何修复我的表单,以便在一个表单中创建具有某些配置文件字段的用户?

感谢您的关注。

EN

回答 1

Stack Overflow用户

发布于 2015-09-07 00:45:48

使用Autoform schema选项时,需要确保您引用的架构已在作用域中定义。没有显示您的模式的原因可能是您没有为User模式注册帮助器。尝试将以下行放在您粘贴的模式定义下:

代码语言:javascript
复制
if (Meteor.isClient) {
    Template.registerHelper('User', User)
}

此外,在开发应用程序和表单时启用Autoform & SimpleSchema调试模式也是一个很好的反应:

代码语言:javascript
复制
if (Meteor.isClient)
    AutoForm.debug()
SimpleSchema.debug = true

在任何development.js文件中,您可能必须在应用程序中定义开发环境。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31627805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档