Skip to content

Commit

Permalink
Teambuilder: Fix desync bugs
Browse files Browse the repository at this point in the history
Fixes #1991

(Removing a move by clicking on it in search didn't actually
remove it from the set.)

Fixes #2134

(Sorting and clicking on a filter would clear the currently
selected pokemon/move textbox, but this was only supposed to
happen when searching for a filter.)
  • Loading branch information
Zarel committed Nov 4, 2023
1 parent fb41336 commit 6ca49c5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,10 @@
},
chartClick: function (e) {
if (this.search.addFilter(e.currentTarget)) {
this.$('input[name=' + this.curChartName + ']').val('').select();
var curChart = this.$('input[name=' + this.curChartName + ']');
// if we were searching for the filter, remove it
if (this.search.q) curChart.val('');
curChart.select();
this.search.find('');
return;
}
Expand All @@ -2926,23 +2929,23 @@
if (this.curChartType === 'move' && e.currentTarget.className === 'cur') {
// clicked a move, remove it if we already have it
var moves = [];
for (var i = 1; i <= 4; i++) {
var $inputEl = this.$('input[name=move' + i + ']');
var curVal = $inputEl.val();
for (var i = 0; i < this.curSet.moves.length; i++) {
var curVal = this.curSet.moves[i];
if (curVal === val) {
this.unChooseMove(curVal);
$inputEl.val('');
delete this.search.cur[toID(val)];
} else if (curVal) {
moves.push(curVal);
}
}
if (moves.length < 4) {
if (moves.length < this.curSet.moves.length) {
this.$('input[name=move1]').val(moves[0] || '');
this.$('input[name=move2]').val(moves[1] || '');
this.$('input[name=move3]').val(moves[2] || '');
this.$('input[name=move4]').val(moves[3] || '');
this.$('input[name=move' + (1 + moves.length) + ']').focus();
this.$('input[name=move' + Math.min(moves.length + 1, 4) + ']').focus();
this.curSet.moves = moves;
this.search.find('');
return;
}
}
Expand Down

0 comments on commit 6ca49c5

Please sign in to comment.