E
E
E2015-04-05 16:31:23
JavaScript
E, 2015-04-05 16:31:23

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;
  }
});

Actually template
<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>

Scheme
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

3 answer(s)
E
E, 2015-04-06
@aylo

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}}

It was not necessary to bind the schema at all, it was enough to specify the Meteor.users collection, and since the type=update form specify the document doc=currentUser

N
nurise, 2015-04-06
@nurise

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

V
Viktor Bogutskii, 2017-03-02
@siteogra

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 question

Ask a Question

731 491 924 answers to any question