Meteor – Condition Attributes with no value error

I just wasted an hour and a half so I figured I’d write a quick blog post to possibly save others who encounter a similar problem some time.

I have a select box and I want the value to pre-populate if the value is already in the collection.

So here’s my dropdown inside my template:

here’s my LeagueItem template (will show the options from the Leagues collection

Here is my controller to make sure the current league is selected if there is a match:

isOptionSelected: function (evt, template) {
var team, league;

// which team are we dealing with?
team = Teams.findOne({_id: Session.get('sTeamId') });

// use the leagueId of that team to search the leagues collection
league = Leagues.findOne({_id: team.leagueId});
// as we loop through all the leagues we check each leagueId
// if the leagueId in the current iteration matches the actual leagueId
// of the team, we have a match
if (this._id == team.leagueId) {
// this will populate the html select option with 'selected'
// attribute so that the value is chosen when template loads
return 'selected';
} else {
return false;

The final product is I just want to have and option tag that will look like this if the team’s league is currently in the dropdown:

And here is where the problem lies.

You will get an error that says something about null:
When isChecked returns null, undefined, or false, the attribute is removed.

I then tried to use a conditional in the attribute:

But then I got this error:
Reactive HTML attributes must either have a constant name or consist of a single {{helper}} providing a dictionary of names and values. A template tag of type BLOCKOPEN is not allowed here.

After researching I found that Spacebars no longer supports block helpers around attributes.

So to fix it I just made sure my controller helper returned ‘selected’ or false.

And my template looked like this:

I have no idea if anyone will encounter this problem or even understand what I just wrote as it’s not the most straight forward explanation. Apologies. But on the rare chance it may help someone, I posted it.

Leave a Reply

Your email address will not be published. Required fields are marked *