I have created an AutoForm update form that I am populating with the contents of a document. I am having a difficult time getting AutoForm to display the email address stored in the document.
<template name="edit_user_form">
{{#autoForm schema=schema id="edit_user_form" type="update" collection=Meteor.users doc=selected_user_doc}}
<fieldset>
{{> afQuickField name="profile.first_name"}}
{{> afQuickField name="profile.last_name"}}
{{> afQuickField name="emails"}}
{{> afQuickField name="status" options="allowed" noselect=true}}
{{> afQuickField name="roles" options="allowed" noselect=true}}
<div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</fieldset>
{{/autoForm}}
</template>
As a result, the Emails input field is populated with "[object Object]".
Since I am only allowing one e-mail per user, what is the correct way to tell AutoForm to populate a form field with an e-mail address? Thanks.
Yes, in meteor accounts, emails are considered an array. You can use this notation from the autoform github's issues:
{{> afQuickField name="emails.0.address"}}
Related
I'm working on dictionary app, and schema have a nested structure.
articles (collection)
-words (array of objects {"note", "word"} )
-translations (array of objects {"translation", "examples"} )
--examples (array of objects {"example", "translation"} ) that means
examples of word usage with it's translation.
The {{> quickForm collection=articles ... }} are working fine, but I want to change template and functionality by some conditions...
I tried to use
{{#autoForm collection=articles id="insertArticleForm" class="article-form" }}
{{#afEachArrayItem name='words'}}
{{> afFieldInput name=this.current.note placeholder='schemaLabel' class="note"}}
{{> afFieldInput name=this.current.word placeholder='schemaLabel' class="word"}}
<button type="button" class="autoform-remove-item"><span class="glyphicon glyphicon-remove"></span></button>
{{/afEachArrayItem}}
<button type="button" class="autoform-add-item" data-autoform-field="words"><span class="glyphicon glyphicon-plus"></span></button>
{{/autoForm}}
But it doesn't work.
It looks like this old issue: Meteor: Custom AutoForm with array of objects
but it seems after some recent updates of Meteor/Autoform, this syntax doesn't work.... and author of plugin doesn't answer on issues for months (
When I changed {{> afFieldInput name=this.current.note }} to {{> afFieldInput name='words.$.note' }} it seems like working , form appears with all need fields, but nothing are submit on the server. Even in this simple example, without nested fields...
{{#autoForm schema="asdf" id="sdfg" type="method" meteormethod="meth"}}
<fieldset>
{{> afQuickField name="startLocation"}}
{{> afQuickField name="destination"}}
{{> afQuickField name="date"}}
{{> afQuickField name="departureTime"}}
{{> afQuickField name="returnTime"}}
{{> afQuickField name="seats" type="number"}}
</fieldset>
<button type="submit" class="btn btn-primary">submit<button>
{{/autoForm}}
The above code generates a form in my Meteor app, however it looks pretty bad (or at least, non-intuitive):
I don't know why this is. In the examples (1, 2) I'm looking at, the form renders in a much more sensical way. How can I get the afQuickField to show the label and the input on separate lines, or at least in another way that makes sense?
I'm using the useraccounts package in my Meteor app. I want an admin to be able to add a new user (and disable signing up through the frontend). Therefore, I have added a Collection with a SimpleSchema as per the suggestion of meteor-collection2. I'm alos using AutoForm to create an 'Add user' page.
<template name="addCustomerProfile">
<div class="container">
<h1>Edit document</h1>
{{#if isReady 'updateCustomerProfile'}}
{{#autoForm collection="Users" id="userForm" type="insert" }}
<fieldset>
{{> afQuickField name='emails.0.address'}}
{{> afQuickField name='emails.0.verified'}}
{{> afQuickField name='services.password'}}
{{> afQuickField name='username'}}
{{> afQuickField name='profile.firstName'}}
</fieldset>
<button type="submit" class="btn btn-primary">Add User</button>
{{/autoForm}}
{{else}}
Nothing
{{/if}}
</div>
</template>
I can add users whenever the 'services.password' is not added to the form, but obviously no default password is set for the user in the Mongo database in that case. How can I add a field so the admin can set a default password for that user (which the user will then be able to change later on).
Why not just forbidClientAccountCreation and sendEnrollmentEmail?
Accounts.config({
forbidClientAccountCreation: true
});
Meteor.methods({
'inviteUser': function (doc) {
check(doc, YourForm);
let userId = Accounts.createUser(doc);
Accounts.sendEnrollmentEmail(userId);
}
});
I am trying to get two afQuickField text fields to display in the same line and from any example I have seen, which is not very many out there, I can not get them to look correct. I have a client form, it has address etc in it. I am trying to get the Suite fiel and the City field to display inline on the same line. I am also trying to get the State and Zip fields on the same line.
I can accomplish this if I have my bootstrap grid set to col-md-6 so that this form is in half the page. The will be inline however they will not be the full width of the col as all the other text fields are and it looks funny. But what I really want is for this form to be in a col-md-4. When I do this it seperates both of these and puts them on seperate lines but again neither are the full length like other text fields. I have attached pictures here of both senarios.
What I am looking for is to have these two fields lineup to be the same width as the other fields around them so they don't stand out like a sore thumb.
I have attached a plnkr of my html doc as well as pasted the applicable code below.
{{#autoForm collection="customers" id="insertCustomer" type="insert"}}
<div class="row customerForm">
<div class="col-md-4 rcorners">
<!-- ************************************************
***** Customer Name and address fields ***********
************************************************ -->
{{> afQuickField name='customerName' template="bootstrap3-horizontal"
input-col-class="col-sm-12 padL-0" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
{{> afQuickField name='customerAddress' template="bootstrap3-horizontal"
input-col-class="col-sm-12 padL-0" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
<div class="form-inline">
{{> afQuickField name='customerSuite'
template="bootstrap3-inline" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
{{> afQuickField name='customerCity'
template="bootstrap3-inline" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
</div>
<div class="form-inline">
{{> afQuickField name='customerState'
template="bootstrap3-inline" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
{{> afQuickField name='customerZip'
template="bootstrap3-inline" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
</div>
{{> afQuickField name='customerPhone1' template="bootstrap3-horizontal"
input-col-class="col-sm-12 padL-0" label-class="sr-only"
afFieldInput-placeholder="schemaLabel"}}
http://plnkr.co/edit/y0v2Xltdfs01wqZS5ZIg
I am using meteoric-autoform and doing an update to my values, The form is not getting populated with existing values and also the update is not happening.
I could also see that the template helper method that I have for fetching the id is not getting invoked at all.
assesmentEdit.js
Template.assesmentEdit.helpers({
assesment: function () {
alert("entered helper");
console.log(template.data.id);
var template = Template.instance();
return Assesments.findOne({_id: template.data.id});
}
});
assesmentEdit.html
<template name="assesmentEdit">
{{#ionModal customTemplate=true}}
{{# autoForm collection="Assesments" id="assesments-edit-form" type="update"}}
<div class="bar bar-header bar-stable">
<button data-dismiss="modal" type="button" class="button button-clear">Cancel</button>
<h2 class="title">Edit Assesment</h2>
<button type="submit" class="button button-positive button-clear">Save</button>
</div>
<div class="content has-header overflow-scroll">
{{> afQuickField name="name" }}
{{> afQuickField name="email"}}
{{> afQuickField name="category"}}
{{> afQuickField name="location"}}
</div>
{{/autoForm}}
{{/ionModal}}
</template>
As you can see in the docs, update forms require a doc attribute.
{{# autoForm doc=assesment collection="Assesments" id="assesments-edit-form" type="update"}}