When using autoform with type="method-update" meteormethod="someMethod" the method will not actually get called.
The autoform I am having trouble with:
{{#autoForm id="archiveIssue" type="method-update" meteormethod="editIssue" collection="Collections.Issues" validation="keyup" doc=doc autosaveOnKeyup="true" resetOnSuccess="true"}}
<fieldset>
{{> afQuickField name="Archived.Archived_By" id="Archived.Archived_By" autocomplete="off"}}
{{> afQuickField name="Archived.Archive_Notes" id="Archived.Archive_Notes" autocomplete="off" rows=5}}
<div>
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#archiveIssue">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</fieldset>
{{/autoForm}}
This is the method that I am trying to call (The PRINT never shows up in the in the server console):
editIssue: function(doc) {
console.log("PRINT");
Collections.Issues.update({
"_id": doc._id
},
{
$set: {
"Archived.Archived": true,
"Archived.Archived_By": doc.Archived_By,
"Archived.Archive_Notes": doc.Archive_Notes
}
});
}
The 2 functions that should help get the doc:
Template.archiveIssue.helpers({
doc: function () {
var tmp = Session.get("archiveDoc");
return tmp;
}
});
Template.archiveIssueModal.events({
"click .archiveButton": function (event) {
Session.set("archiveDoc", this);
}
});
Schemas
Schema.Archived = new SimpleSchema({
Archived: {
type: Boolean,
optional: true
},
Archived_By: {
type: String,
optional: true
},
Archive_Notes: {
type: String,
max: 200,
optional: true
}
});
Schema.Issues = new SimpleSchema({
Description: {
type: String,
max: 500,
optional: true
},
Comments: {
type: [Schema.Comments],
max: 500,
optional: true
},
User: {
type: String,
label: "User",
optional: true
},
Archived: {
type: Schema.Archived,
optional: true
},
});
Not sure if you need an answer now.
You need to define with Meteor.methods like this.
Meteor.methods({
demoSubmission: function () {
Related
I created in meteor.js a user profile edit page based on autoform and simpl-schema packages. I also added Tracker to schema.
I wanted to make field Profile.Username required but it's validate when field is empty. This field is also unique and handling this property works good.
Also Email field is required and there Tracker works good.
Here is my code:
users.js
import { Mongo } from 'meteor/mongo';
import { Tracker } from 'meteor/tracker';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
Schema.User = new SimpleSchema({
emails: {
type: Array,
optional: true
},
'emails.$': {
type: Object,
optional: true,
},
'emails.$.address': {
type: String,
regEx: SimpleSchema.RegEx.Email
},
'emails.$.verified': {
type: Boolean,
optional: true,
autoform: {
type: 'boolean-checkbox'
}
},
createdAt: {
type: Date,
autoValue: function() {
return new Date();
},
autoform: {
type: 'hidden'
}
},
profile: {
type: Schema.UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true,
autoform: {
type: 'hidden'
}
}
}, {tracker: Tracker});
Meteor.users.attachSchema(Schema.User);
Meteor.users.allow({
insert: function () { return true; },
update: function () { return true; },
remove: function () { return true; }
});
profile.js
import { Mongo } from 'meteor/mongo';
import { Tracker } from 'meteor/tracker';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
Schema = {};
Schema.UserProfile = new SimpleSchema({
username: {
type: String,
label: 'Username',
unique: true,
},
firstName: {
type: String,
optional: true
},
lastName: {
type: String,
optional: true
},
birthday: {
type: Date,
optional: true,
autoform: {
type: 'bootstrap-datepicker',
datePickerOptions: {
autoclose: true
}
}
},
gender: {
type: String,
optional: true,
autoform: {
type:'select-radio',
options: function () {
return [
{ label: 'Male', value: 'Male'},
{ label: 'Female', value: 'Female'},
];
},
}
}
}, {tracker: Tracker});
and ProfileEdit.html
<template name="ProfileEdit">
{{> Header}}
{{> SideNav}}
<div class="main-layout">
<legend>Update Profile</legend>
{{#if Template.subscriptionsReady}}
{{# autoForm id="profileEdit" collection="Meteor.users"
doc=currentUser type="update"}}
{{> afObjectField name="emails.0"}}
{{> afObjectField name="profile"}}
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
{{/autoForm}}
{{/if}}
</div>
</template>
Please, help me.
I'm on the single page of a collection item (gigs) and I want to push to the item's array on the 'show' page I have. The idea is that I have a modal that pops up below and you can add another entry.
I've tried this using aldeed autoform but I get no push to the collection item. Why?
<!-- Modal Structure -->
<div id="modal1" class="modal bottom-sheet">
<div class="container">
<div class="modal-footer">
CLOSE
</div>
<div class="modal-content">
{{#autoForm collection="Gigs" id="myForm" }}
{{#afEachArrayItem name="gear"}}
{{> afQuickField name=this.current.item}}
{{> afQuickField name=this.current.description}}
{{/afEachArrayItem}}
<button type="submit" class="btn update-gig">Add</button>
{{/autoForm}}
</div>
</div>
</div>
Note I have tried to change the js too.
Gigs.allow({
insert: function(userId, doc){
return !!userId;
},
update: function(userId, doc){
return !!userId;
}
})
And added a method for the form in js
Meteor.methods({
addGig: function(id, gear){
Gigs.update(id,{ $addToSet: { gear: gear } })
}
});
And called it in the client trying:
Template.Gig.events({
'submit .update-gig': function(){
Meteor.call('addGig', this._id, this.gear)
}
})
Simple Schema
Gear = new SimpleSchema({
item: {
type: String,
label: "Item",
optional: false
},
description: {
type: String,
label: "Description",
optional: true
},
user:{
type: String,
label: "User",
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Created At",
autoValue: function(){
return new Date()
},
autoform: {
type: "hidden"
}
}
});
GigsSchema = new SimpleSchema({
gig: {
type: String,
label: 'Gig Name'
},
location: {
type: String,
label: 'Location'
},
gear: {
type: [Gear]
},
user:{
type: String,
label: "User",
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Created At",
autoValue: function(){
return new Date()
},
autoform: {
type: "hidden"
}
}
});
UPDATE: I have this working but if anyone has a simpler method using autoform that would be greatly appreciated!!
client code:
'submit .update-gig-form': function(event){
event.preventDefault();
var id = FlowRouter.getParam('id');
var item = event.target.form_item.value;
var desc = event.target.form_desc.value;
// jquery materialize css to close modal on page
$('#modal1').closeModal();
Meteor.call('addGear', id, item, desc);
//reset form
event.target.form_item.value = '';
event.target.form_desc.value = '';
}
server code
Meteor.methods({
addGear: function(id, form_item, form_desc){
console.log('yay method run');
Gigs.update(id,{ $addToSet: { gear: {
item: form_item,
description: form_desc
}}
});
}
});
Introduction
I am working with kendo-ui.Data loading perfectly in grid using web-api.I am doing one thing more which is to "Post" or create new record.I have set this up using This Example.
Problem
Now, when i add new record/item and then click on submit button(which only show my alerts and console messages) my insertion failed and i don't have related error messages. I have checked schema, modal etc but again can't find any problem.
Can this be a modal issue?
HTM
<div id="form-container">
<div class="demo-section k-content">
<input type='text' data-bind='value:Name' name='Project Name' />
<input data-value-primitive="true" data-source="dataSourceList" data-bind="value:Status" data-role="dropdownlist" />
<button data-bind="click: save" class="k-button k-primary">Submit</button>
</div>
</div>
Modified Script
var viewModel = kendo.observable({
dataSourceList: new kendo.data.DataSource({
transport: {
read:
{
url: crudServiceBaseUrl + "dropdown/projectstatus",
dataType: "json",
},
create: {
url: function () {
return crudServiceBaseUrl + "Project/?firmid=" + firmid + "&createdby=" + clientid
},
type: "POST"
},
batch: true,
schema: {
model: {
id: "ProjectId",
fields: {
ProjectId: { from: "ProjectId", editable: true, nullable: true, type: "guid" }
, Status: { from: "Status", editable: true, nullable: true, type: "string" }
, Name: { from: "Name", editable: true, nullable: true, type: "string" }
}
}
},
}
}),
save: function () {
this.dataSourceList.add({ Status: this.get("Status"), Name: this.get("Name")});
console.log(this.dataSourceList.add({ Status: this.get("Status"), Name: this.get("Name") }));
this.dataSourceList.sync();
console.log(this.dataSourceList.transport.options.schema);
},
});
kendo.bind($("#form-container"), viewModel);
Console messages Screen(in code above)
I have been trying for some time but couldn't solve this problem.If someone has idea about this please help or any reference, it will be appreciated.Thanks for your time.
After following the README in the autoform summernote package, whenever I try to submit the form I get this error:
Uncaught TypeError: undefined is not a function
Clicking on the error shows this code:
AutoForm.addInputType('summernote', {
template: 'afSummernote',
valueOut: function() {
return this.code(); //This as the offending line (marked with an x)
}});
I am not sure if I am doing something wrong or it is the package
schema
//Creating a new Collection
Todos = new Mongo.Collection("Todos");
//Defining the schema
Todos.attachSchema(new SimpleSchema({
name: {
type:String,
label: "Name",
max:200
},
description: {
type:String,
label: "Description",
autoform: {
afFieldInput: {
type: 'summernote'
}
}
},
todo_type: {
type: String,
label: "Todo Type",
allowedValues: ['normal', 'survey'],
defaultValue: "normal",
autoform: {
type: "select",
options: function () {
return [
{label: "normal", value: "normal"},
{label: "survey", value: "survey"}
];
}
}
},
survey_questions: {
type: [Number],
label: "Survey Questions",
optional: true,
autoform: {
type: "hidden"
},
},
user_id:{
type: String,
autoform: {
type: "hidden",
label: false
},
autoValue: function(){
if (this.isInsert) {
return Meteor.userId();
} else if (this.isUpsert) {
return {$setOnInsert: Meteor.userId()};
} else {
this.unset();
}
},
denyUpdate:true
},
last_modified: {
type: Date,
autoform: {
type: "hidden",
label: false
},
autoValue: function () {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset();
}
}
},
created_at: {
type: Date,
autoform: {
type: "hidden",
label: false
},
autoValue: function () {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset();
}
},
denyUpdate: true
}
}));
.html
<template name='todo_create'>
{{#autoForm collection="Todos" id="todo_create" type="insert"}}
<fieldset>
<legend>Add a Todo</legend>
<div style="float:left; margin-top:10px;">
<div class="textField">
{{> afQuickField name='name'}}
</div>
<div class="textField" style="margin-left:20px;">
{{> afQuickField name='todo_type'}}
</div>
</div>
<div class="descriptionText">
{{> afFieldInput name='description'}}
</div>
</fieldset>
<button type="submit" class="btn btn-primary">Add a Todo</button>
{{/autoForm}}
<div class="tableHolder">
{{> tabular table=TabularTables.Todos class="table table-striped table-bordered table-condensed"}}
</div>
</template>
I'm using accounts-ui for the login system. I want to a create a profile form which I've got displaying using autoform. When I try to submit the form the params are passed in the URL and the page refreshes but nothing is saved to the collection.
Any ideas?
Here's my schema (I've also tried just using a UserProfile schema but that didn't work)
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>
This is really late but if anyone need this, the issue you where having is you never gave it the user collection:
{{#autoForm
collection='Meteor.users' //this was your issue
id="signupForm"
doc=editingDoc
type="update"
}}
If you wanted to you could even limit the form to just the profile with:
{{#autoForm
collection='Meteor.users'
schema="Schema.UserProfile" //both collection & schema will render schema
id="signupForm"
doc=editingDoc
type="update"
}}