javascript - Will a Meteor Helper that reads a value from an element automatically be re-executed when that element's value changes? -
i have need first populate set of select elements values, so:
<select class="jobloc" id="date1shift1jobloc1" name="date1shift1jobloc1"> {{#each joblocations}} <option value={{jl_jobloc}}>{{jl_jobloc}}</option> {{/each}} </select>
...but update (replacing initial superset of joblocs subset) when another, related select element changes.
the helper returns set of documents based on value of related select element, (pseudocode):
template.tblscheduler.helpers({ joblocations: function() { var worker = $('#worker').val; if (worker == '') { return joblocations.find(); // return } else { return joblocations.find({ jl_workerid: worker }); // worker selected; use return subset } } });
when template first rendered, "date1shift1jobloc1count" select element populated joblocs; if worker selected, though, options in "date1shift1jobloc1count" should cleared out , replaced appropriate subset.
the question is, work automatically, due fact meteor sees helper relies on value of "#worker" select element? hope so...but expect i'm hoping much. if doubts well-founded, how can helper re-run, , template re-render? need template event handler, this:
template.tblscheduler.events({ "change #worker": function (event) { // possible call joblocations helper here? } });
? or have "manually" there, (pseudocode):
template.tblscheduler.events({ "change #worker": function (event) { var worker = $('#worker').val; var arrayofdocs = meteor.call('getjoblocsforworker(worker))'); // assign values in arrayofdocs "date1shift1jobloc1" select element } });
or there way?
jquery elements being non-reactive data sources , since helpers depend on believe best bet wrap value in reactivevar:
var worker = new reactivevar('') template.tblscheduler.helpers({ joblocations : function() { var workervalue = worker.get() //<- register dependency //your cursor logic here } }) template.tblscheduler.events({ 'change #worker' : function() { worker.set($('#worker').val) } })
you might want _.debounce
change
event handling user not see whole ui blinking , updating @ every letter (s)he types.
Comments
Post a Comment