Skip to content

Commit

Permalink
Catch invalid number of teams in init
Browse files Browse the repository at this point in the history
  • Loading branch information
teijo committed Oct 19, 2016
1 parent c1c9862 commit 7c2d095
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/jquery.bracket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,10 @@
if (opts.save && (opts.onMatchClick || opts.onMatchHover)) {
$.error('Match callbacks may not be passed in edit mode (in conjunction with save callback)');
}
const log2 = Math.log2(opts.init.teams.length);
if (log2 !== Math.floor(log2)) {
$.error(`"teams" property must have 2^n number of team pairs, i.e. 1, 2, 4, etc. Got ${opts.init.teams.length} team pairs.`);
}
opts.dir = opts.dir || 'lr';
opts.init.teams = !opts.init.teams || opts.init.teams.length === 0 ? [[null, null]] : opts.init.teams;
opts.init.teams = opts.init.teams.map(ts => ts.map(t => Option.of(t)));
Expand Down

0 comments on commit 7c2d095

Please sign in to comment.