meteor onRendered not called

353 views Asked by At

I’m trying to have a reactive bootstrap selectpicker but I have a weird behaviour: An event has to change the options of the select but it works only after the first event which is not working because the app doesn’t go into the onRendered part…

This is the onRendered part:

var renderTimeout = false;
Template.printerselect.onRendered( function(){
  if (renderTimeout !== false) {
    Meteor.clearTimeout(renderTimeout);
  }
  renderTimeout = Meteor.setTimeout(function() {
    $('#printerName').selectpicker("refresh");
    renderTimeout = false;
  }, 10);
});

Template.printerSetupForm.onRendered( function(){
  $('.selectpicker').selectpicker();
});

here, the templates :

<div class="col-lg-3 col-md-4 col-xs-12 form-group">
  <label>COMPANY</label>
  <select id="printerCompany" class="form-control selectpicker" name="printer[company]">
    <option selected="true" disabled="disabled" value={{company}}>
      Please Select A Printer Company
    </option>
    {{#each Companies}}
      <option value="{{company}}" {{printerCompanySelected company}}> {{company}}</option>
    {{/each}}
  </select>
 </div>
 <div class="col-lg-3 col-md-4 col-xs-12 form-group">
   <label>PRINTER NAME</label>
   <select id="printerName" class="form-control selectpicker" name="printer[name]">
     <option selected="true" disabled="disabled" value={{name}}>
       Please Select A Printer
     </option>
     {{#each Names}}
       <!--<option value="{{name}}" {{printerNameSelected name}}>
         {{name}}
       </option>-->
       {{>printerselect}}
     {{/each}}
   </select>
 </div>

<template name="printerselect">
    <option value="{{name}}"> {{name}} </option>
</template>

The refresh is called when the page is rendered.

Then I change the company which changes some Session variables and reactively to change the name select options but the refresh is not called so that doesn’t come to the onrendered part.

But when I change again the company it’s working, the onRendered part is called.

Weird thing is that even if this is not displaying the right names, when i’m choosing a name which doesn’t match with the company, the select chooses the right one.

Sorry for my english in advance, I did my best.

Thanks you in advance !

EDIT: Names helper :

Names: () => {
  company=Session.get('printer').company;
  if(typeof company!='undefined') {
    return Printers.find({company: company}).fetch();
  } else {
    return Printers.find().fetch();
  }
}
1

There are 1 answers

0
FlorianD On

I set the Session variable 'printers' with an empty field. When I select a company, it's now working but without company, I don't get any printers because I don't have to test company with 'undefined' but with empty field.

So I changed to test with empty field and it isn't working anymore...

So weird that a test could cancel a onRendered, this must be an issue with the Mongo stuff.

I will continue to search on it.