Skip to content

Commit

Permalink
Merge pull request aldeed#36 from fcmatteo/master
Browse files Browse the repository at this point in the history
Updated example for working with last autoform version
  • Loading branch information
aldeed committed Apr 10, 2015
2 parents 8353b1e + cb9dfd7 commit c047c34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Docs.attachSchema(mySchema);
Change the html to reflect the server method type:
```html
<template name="insertForm">
{{#autoForm id="insertForm" type="method" collection="Docs"}}
{{#autoForm id="insertForm" type="method" collection="Docs" meteormethod="myServerMethod"}}
{{> afQuickField name="name"}}
{{> afQuickField name="fileId" type="cfs-file" collection="files"}}
<button type="submit">Submit</button>
Expand All @@ -118,10 +118,10 @@ AutoForm.addHooks(
["insertForm"],
{
before : {
myServerMethod: CfsAutoForm.Hooks.beforeInsert
method: CfsAutoForm.Hooks.beforeInsert
},
after : {
myServerMethod: CfsAutoForm.Hooks.afterInsert
method: CfsAutoForm.Hooks.afterInsert
}
}
);
Expand Down
18 changes: 12 additions & 6 deletions cfs-autoform-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ Hooks = {
// cleanup uploaded files data
elems.removeData("cfsaf_uploaded-files");
},
beforeUpdate: function(_id, doc, template){
var self = this;
beforeUpdate: function(doc){
var self = this, template = this.template;
if (!AutoForm.validateForm(this.formId)) {
return false;
}
Expand All @@ -168,9 +168,8 @@ Hooks = {
// Get schema key that this input is for
var key = elem.attr("data-schema-key");

// no matter what, we want to delete the dummyId value
//delete doc[key];
CfsAutoForm.Util.deepDelete(doc,key);
//Maintain current key
doc.$set[key] = self.currentDoc[key];

// Get list of files that were attached for this key
var fileList = elem.data("cfsaf_files");
Expand All @@ -179,12 +178,18 @@ Hooks = {
if (fileList) {
// add all files to total count
totalFiles += fileList.length;
//we delete the id only if we uploaded another file
//delete doc[key];
CfsAutoForm.Util.deepDelete(doc,key);
}

// Otherwise it might be a multiple files field
else {
var fileListList = elem.data("cfsaf_files_multi");
if (fileListList) {
//we delete the id only if we uploaded another file
//delete doc[key];
CfsAutoForm.Util.deepDelete(doc,key);
// make a note that it's an array field
arrayFields[key] = true;
// add all files to total count
Expand Down Expand Up @@ -295,7 +300,8 @@ Hooks = {
});
});
},
afterUpdate: function(error, result, template){
afterUpdate: function(error, result){
var template = this.template;
var elems = template.$('.cfsaf-hidden');
if (error) {
CfsAutoForm.deleteUploadedFiles(template);
Expand Down

0 comments on commit c047c34

Please sign in to comment.