Show & Hide some elements based on input - radio buttons

I’ve published publications on the server/server.js file and subscribed them on client/client.js.

If it was anything to do with pub/sub issue, I don’t think I’d have the button event working at all… I mean it works perfect when one clicks a radio button. Problem is that nothing shows on the page render, before one clicks any radio button. So are you sure the whole function runs before the “click” event is triggered - radio button pressed???

Yes, autopublish was removed long ago.

Is the template you listed originally still correct?

<template name="myTemplate">  
    <div>
      <input type="radio" name="myBut" value="showAll" checked="checked">All
      <input type="radio" name="myBut" value="showToMe">To Me
      <input type="radio" name="myBut" value="showByMe">By Me
    </div>
      {{#each myHelper}}
          {{list-item}}   
      {{/each}}
</template>

I assume the template name is actually “requestsList” to match your events?

Yes, exactly. Sorry I tried to name the markup more semantically to make sense here. Forgot to change…

So, to confirm the running of the helpers when button action is out of the picture, change your helper to:

Template.requestsList.helpers({
  myHelper: function () {
    return [
      {'list-item': 'cat'},
      {'list-item': 'dog'}
    ]
  }
});

So, an array of objects each having a list-item member.

Edit: as I type this I wonder whether you’ve ensured your subscription is ready? The above change makes it guaranteed ready, so if it works (as I expect it to) it may just point to your subscription needing wrapping in an autorun to pick up the ready state when it happens.

Hi @robfallows,

Indeed, I use these helper wrapping my helper in the template.

{{#if isSubReady 'requests'}}
  --previously embedded code--
{{else}}
  loading...
 {{/if}}

And I don’t see loading… So I assume sub is ready. :blush:

This is one of the arillo:flow-router-helpers?

If you check the code for these you will see that the isSubsReady helper is sugar for flow-router’s FlowRouter.subsReady(). If you read the documentation for that you will see that @arunoda wraps this in a Tracker.autorun():

After you’ve registered your subscriptions, you can reactively check for the status of those subscriptions like this:

Tracker.autorun(function() {
  console.log(“Is myPost ready?:”, FlowRouter.subsReady(“myPost”));
  console.log(“Does all subscriptions ready?:”, FlowRouter.subsReady());
});

The point being a subscription can be “ready” (set up and ready to go) even if no data is available. So, in order to ensure that you get to see the data as it becomes available, you still need to wrap the check in an autorun as arunoda recommends.

Incidentally, for v3 of flow-router, arunoda has said that subscription management will be removed:

FlowRouter also has it’s own subscription registration mechanism. We will remove this in version 3.0.

I highly recommend reading the subscription management section of the flow-router repo.

Aha OK, cool. I’m at work now, and will try your previously posted code when I get home.

Thanks a lot for the tips!