I'am trying to implement 2 selects in a template. One is for selecting a single category from all of Categories collection, and the other is for selecting a set of skills related to that particular category. So, the latter is dependent on the first. What I think is the right way of doing that is to have a session variable to store selected category id upon select change event and helper function that reactively return cursor with that id. My code looks like...
<template name="createPost">
<select id="categories" name="category">
{{#each categories}}
<option value="{{_id}}">{{categoryName}}</option>
{{/each}}
</select>
...
<select id="skills" name="skills">
{{#each skills}}
<option value="{{_id}}">{{skillName}}</option>
{{/each}}
</select>
</template>
Template.createPost.helpers
categories: -> Categories.find()
getCategory = ->
Session.get 'selectedCategory'
Tracker.autorun ->
skills: ->
Skills.find {category: getCategory}
Template.createPost.events
"change #categories": (e) ->
Session.set 'selectedCategory', e.target.value
...........
First select is populated with categories. However, when I choose a category, related skills are not shown in the second select. Any idea what's wrong with this code, sorry I am still pretty new to meteor. Thanks in advance.
tracker.autorun? - challettSkills.find({})in the console after selecting a category? - challettinsecurepackage? If not what does your subscription/publication look like? - challett