From 80521b2b56091ec5b5847acfd726912c883f77dd Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sat, 4 Nov 2023 17:14:59 +0000 Subject: [PATCH] Teambuilder: Fix desync bugs 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.) --- js/client-teambuilder.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/js/client-teambuilder.js b/js/client-teambuilder.js index 871043bbe9f..ed933379a6f 100644 --- a/js/client-teambuilder.js +++ b/js/client-teambuilder.js @@ -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; } @@ -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; } }