I've been trawling SO questions for an answer to something that should be very simple but for the life of me I cannot figure it out.
Basically I have a meteor-autoform with two select controls:
<template name="processFormTemplate">
{{#autoForm id="processForm" collection="Processes" type=formAction doc=doc validation="blur"}}
<div class="col-md-12">
{{> afQuickField name="elementId" options=elements}}
{{> afQuickField name="categoryId" options=categories}}
{{> afQuickField name="title"}}
{{> afQuickField name="desc" rows=4}}
</div>
{{>formButtons}}
{{/autoForm}}
</template>
These then have helpers to populate the options:
Template.processFormTemplate.helpers({
elements: function() {
return getFormElements();
},
categories: function(elementId) {
return getFormCategories(this.doc.elementId);
}
});
lib/methods.js
getFormElements = function() {
var options = [];
Elements.find({}, {sort: {ref:1}}).forEach(function (element) {
options.push({
label: element.title, value: element._id
});
});
return options;
};
getFormCategories = function(elementId) {
var options = [];
var filter = {};
if (!isBlank(elementId)) {
filter.elementId = elementId;
}
Categories.find(filter, {sort: {ref:1}}).forEach(function (d) {
options.push({
label: d.title, value: d._id
});
});
return options;
};
Now I know this isn't working because the helper isn't reactive, however I don't know how to change this behaviour. I've also tried hooking into the 'change' event but this never fires for some reason:
Template.processFormTemplate.events({
'change #elementId': function(e) {
console.log($('[name="elementId"]').val() + ' is now selected');
}
});
The required behaviour is that when a new elementId is selected in the first list, the list of options in the second should be refreshed based on the selected elementId.
Any help much appreciated.
Thanks, David