Meteor.call from the client

With our method ready to go we can update the client to use it:

client/views/games.js

...
  "submit form.form-create": function(e, tpl){
    e.preventDefault();
    var teamOneId = tpl.$("select[name=teamOne]").val();
    var teamTwoId = tpl.$("select[name=teamTwo]").val();

    Meteor.call('gamesInsert', teamOneId, teamTwoId, function(error, response){
      if(error){
        alert(error.reason);
        Session.set('isCreatingGame', true);
        Tracker.afterFlush(function(){
          tpl.$("select[name=teamOne]").val(teamOneId);
          tpl.$("select[name=teamTwo]").val(teamTwoId);
        });
      }
    });

    Session.set('isCreatingGame', false);
  }
...

Here I use the same technique for error handling as I did in the team creation handler in a previous chapter; waiting for the tracker to complete it's flush and add the form to the DOM before modifying the select elements.