【问题标题】:What do I need to do to this Meteor code to update content using autoform?我需要对此 Meteor 代码执行什么操作才能使用 autoform 更新内容?
【发布时间】:2015-01-14 11:25:59
【问题描述】:

我正在为登录系统使用accounts-ui。我想创建一个使用 autoform 显示的配置文件表单。当我尝试提交表单时,参数在 URL 中传递并且页面刷新但没有保存到集合中。

有什么想法吗?

这是我的架构(我也尝试过仅使用 UserProfile 架构,但没有奏效)

    Schema = {};

Schema.UserProfile = new SimpleSchema({
    firstName: {
        type: String,
        regEx: /^[a-zA-Z-]{2,25}$/
    },
    lastName: {
        type: String,
        regEx: /^[a-zA-Z]{2,25}$/
    },
    gender: {
        type: String,
        allowedValues: ['Male', 'Female']
    },
    bio: {
        type: String,
    },
    avatar: {
        type: String,
    },
    pinCode: {
        type: Number,
        min: 7,
        max: 7
    },
    phoneNumber: {
        type: Number,
        min: 9,
        max: 10
    }
});

Schema.User = new SimpleSchema({
    _id: {
        type: String,
        regEx: SimpleSchema.RegEx.Id
    },
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    createdAt: {
        type: Date
    },
    profile: {
        type: Schema.UserProfile,
    },
    services: {
        type: Object,
        optional: true,
        blackbox: false
    }
});

Meteor.users.attachSchema(Schema.User);

 Template.signupForm.helpers({
  users: function () {
  return Meteor.users;
 },
 userSchema: function () {
  return Schema.User;
 }
});

/* as an idea ....
Template.signupForm.editingDoc = function () {
  return Meteor.users.find({_id: Meteor.userId()});
};
*/



//template
<template name="signupForm">
 <div class="panel-body">
   {{#autoForm schema=userSchema id="signupForm" doc=editingDoc  type="update"}}
 <fieldset>
   {{> afObjectField name='profile'}}
 </fieldset>
 <button type="submit" class="btn btn-primary">Insert</button>
 {{/autoForm}}
 </div>
</template>

【问题讨论】:

  • 我在 collection=users 中添加并删除了 schema=userSchema。参数不再在 URL 中传递,页面也不会重新加载。但是,没有任何内容输入到用户配置文件中。还更改了 type="insert" 但没有效果。

标签: javascript meteor


【解决方案1】:

这真的很晚了,但如果有人需要这个,你遇到的问题是你从来没有给它用户集合:

{{#autoForm 
  collection='Meteor.users'  //this was your issue
  id="signupForm" 
  doc=editingDoc  
  type="update"
}}

如果您愿意,您甚至可以将表单限制为仅配置文件:

{{#autoForm 
   collection='Meteor.users' 
   schema="Schema.UserProfile" //both collection & schema will render schema
   id="signupForm" 
   doc=editingDoc  
   type="update"
}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多