Answer the question
In order to leave comments, you need to log in
How to update Meteor.users fields via autoform?
I'm trying to make a user profile page with the ability to change data. But when you click on the button, it gives an error in the browser console, well, of course, the data is not recorded. "Error: AutoForm: You must specify a collection when form type is insert." . Tell me where is my bug?
Template.accountForm.helpers({
userSchema: function () {
return Schema.User;
}
});
<template name="accountForm">
<div class="panel-body">
{{#autoForm schema=userSchema collection=users id="accountForm" type="update" doc=this}}
<fieldset>
{{> afObjectField name='profile'}}
</fieldset>
<button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}
</div>
</template>
Schema = {};
Schema.UserProfile = new SimpleSchema({
name: {
type: String
},
lastName: {
type: String
},
gender: {
type: String,
allowedValues: ['Male', 'Female']
},
company: {
type: String,
}
});
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);
Answer the question
In order to leave comments, you need to log in
Update
The error was here:
{{#autoForm collection='Meteor.users' doc=currentUser type='update' id='accountForm'}}
{{> afQuickField name='profile'}}
<button type='submit' class="btn btn-primary">Save profile</button>
{{/autoForm}}
I would check how it renders {{> afObjectField name='profile'}}
. Is there a data-schema-key in there?
I would re-read the docks again: one , two
If it helps anyone:
{{#autoForm
collection="Colors"
doc=currentColor
id="updatePostForm"
class="form-inline"
meteormethod="color.update"
}}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question