Skip to content

Commit b502cb0

Browse files
committed
Allow user to specify a DDP Connection to use when calling Meteor methods
Manual merge closes #946; thanks @patrickleet
1 parent ed56124 commit b502cb0

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ set (the same effect as setting a `value` attribute on each field within the for
362362
* `validation`: Optional. See the "Fine Tuning Validation" section.
363363
* `template`: Optional. See the "Templates" section.
364364
* `type`: Optional. The form type. Default if not provided is "normal". See [Form Types](#form-types).
365-
* `meteormethod`: Optional. When `type` is "method", indicate the name of the
365+
* `meteormethod`: Optional. When `type` is "method" or "method-update", indicate the name of the
366366
Meteor method in this attribute.
367+
* `ddp`: Optional. When `type` is "method" or "method-update", provide an alternative DDP Connection that should be used to call the Meteor method in this attribute.
367368
* `resetOnSuccess`: Optional. The form is automatically reset
368369
for you after a successful submission action. You can skip this by setting this
369370
attribute to `false`.
@@ -647,6 +648,8 @@ Use the `scope` attribute on your form to define the array field into which the
647648

648649
Will call the server method with the name you specify in the `meteormethod` attribute. Passes a single argument, `doc`, which is the document resulting from the form submission.
649650

651+
You may optionally specify a DDP Connection in the `ddp` attribute. If you do, the method will be called using the DDP connection provided.
652+
650653
The method is not called until `doc` is valid on the client.
651654

652655
**You must call `check()` in the method or perform your own validation since a user could bypass the client side validation.**
@@ -658,6 +661,8 @@ Will call the server method with the name you specify in the `meteormethod` attr
658661
* `modifier`: the modifier object generated from the form values
659662
* `documentId`: the `_id` of the document being updated
660663

664+
You may optionally specify a DDP Connection in the `ddp` attribute. If you do, the method will be called using the DDP connection provided.
665+
661666
The method is not called until `modifier` is valid on the client.
662667

663668
**You must call `check()` in the method or perform your own validation since a user could bypass the client side validation.**

formTypes/method-update.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ AutoForm.addFormType('method-update', {
2626
if (valid === false) {
2727
c.failedValidation();
2828
} else {
29-
// Call the method
30-
Meteor.call(c.formAttributes.meteormethod, updateDoc, c.docId, c.result);
29+
// Call the method. If a ddp connection was provided, use
30+
// that instead of the default Meteor connection
31+
var ddp = c.formAttributes.ddp;
32+
if (ddp && ddp.call && typeof ddp.call === 'function') {
33+
ddp.call(c.formAttributes.meteormethod, updateDoc, c.docId, c.result);
34+
} else {
35+
Meteor.call(c.formAttributes.meteormethod, updateDoc, c.docId, c.result);
36+
}
3137
}
3238
});
3339
},

formTypes/method.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ AutoForm.addFormType('method', {
2626
if (valid === false) {
2727
c.failedValidation();
2828
} else {
29-
// Call the method
30-
Meteor.call(c.formAttributes.meteormethod, doc, c.result);
29+
// Call the method. If a ddp connection was provided, use
30+
// that instead of the default Meteor connection
31+
var ddp = c.formAttributes.ddp;
32+
if (ddp && ddp.call && typeof ddp.call === 'function') {
33+
ddp.call(c.formAttributes.meteormethod, doc, c.result);
34+
} else {
35+
Meteor.call(c.formAttributes.meteormethod, doc, c.result);
36+
}
3137
}
3238
});
3339
},

0 commit comments

Comments
 (0)