From 4f20fece397e941345778f099bcc9797c6aaf50a Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 10 Apr 2025 13:59:47 -0400 Subject: [PATCH 1/2] Migrate jQuery.change --- .../static/js/modules/audit-category-sub-category.js | 2 +- fec/fec/static/js/modules/audit_tags.js | 4 ++-- fec/fec/static/js/modules/dropdowns.js | 2 +- fec/fec/static/js/modules/election-search.js | 2 +- fec/fec/static/js/modules/filters/date-filter.js | 10 +++++----- fec/fec/static/js/modules/filters/election-filter.js | 8 ++++---- fec/fec/static/js/modules/filters/filter-base.js | 2 +- fec/fec/static/js/modules/filters/filter-typeahead.js | 2 +- fec/fec/static/js/modules/filters/select-filter.js | 2 +- fec/fec/static/js/modules/filters/text-filter.js | 2 +- fec/fec/static/js/modules/filters/toggle-filter.js | 2 +- .../static/js/modules/filters/validate-date-filters.js | 4 ++-- fec/fec/static/js/modules/tables.js | 4 ++-- fec/fec/static/js/modules/top-entities.js | 2 +- fec/fec/tests/js/checkbox-filter.js | 10 +++++----- fec/fec/tests/js/contact-form.js | 4 ++-- fec/fec/tests/js/cycle-select.js | 6 +++--- fec/fec/tests/js/date-filter.js | 6 +++--- fec/fec/tests/js/election-search.js | 10 +++++----- fec/fec/tests/js/statistical-summary-archive.js | 4 ++-- fec/fec/tests/js/toggle-filter.js | 4 ++-- fec/fec/tests/js/typeahead-filter.js | 4 ++-- 22 files changed, 48 insertions(+), 48 deletions(-) diff --git a/fec/fec/static/js/modules/audit-category-sub-category.js b/fec/fec/static/js/modules/audit-category-sub-category.js index 72033de171..d61e07ef72 100644 --- a/fec/fec/static/js/modules/audit-category-sub-category.js +++ b/fec/fec/static/js/modules/audit-category-sub-category.js @@ -7,7 +7,7 @@ import { buildUrl } from './helpers.js'; export function auditCategorySubcategory() { - $('#primary_category_id').change(function() { // TODO: jQuery deprecation + $('#primary_category_id').on('change', function() { var $select = $('#sub_category_id'); $.getJSON( buildUrl(['audit-category'], { diff --git a/fec/fec/static/js/modules/audit_tags.js b/fec/fec/static/js/modules/audit_tags.js index c1b1edd26a..5a96809ee8 100644 --- a/fec/fec/static/js/modules/audit_tags.js +++ b/fec/fec/static/js/modules/audit_tags.js @@ -6,7 +6,7 @@ import { default as auditCategoryTemplate } from '../templates/audit_tags.hbs'; export default function auditTags() { $('.data-container__tags').prepend(auditCategoryTemplate); $('.tag__category.sub').css('visibility', 'hidden'); - $('#primary_category_id').change(function() { // TODO: jQuery deprecation + $('#primary_category_id').on('change', function() { const current_category = $('#primary_category_id option:selected').text(); $('.tag__category.sub').css('visibility', 'hidden'); $('.tag__item.primary').contents()[0].nodeValue = `Findings and issue category: ${current_category}`; @@ -15,7 +15,7 @@ export default function auditTags() { : $('.tag__item.primary button').show(); }); - $('#sub_category_id').change(function() { // TODO: jQuery deprecation + $('#sub_category_id').on('change', function() { const current_sub = $('#sub_category_id option:selected').text(); $('.tag__item.sub').contents()[0].nodeValue = `Sub Category: ${current_sub}`; }); diff --git a/fec/fec/static/js/modules/dropdowns.js b/fec/fec/static/js/modules/dropdowns.js index 0d1c0762f1..9a3baf934f 100644 --- a/fec/fec/static/js/modules/dropdowns.js +++ b/fec/fec/static/js/modules/dropdowns.js @@ -129,7 +129,7 @@ Dropdown.prototype.handleCheckKeyup = function(e) { if (e.keyCode === KEYCODE_ENTER) { $(e.target) .prop('checked', true) - .change(); // TODO: jQuery deprecation + .trigger('change'); } }; diff --git a/fec/fec/static/js/modules/election-search.js b/fec/fec/static/js/modules/election-search.js index a81dac7970..9fd8523095 100644 --- a/fec/fec/static/js/modules/election-search.js +++ b/fec/fec/static/js/modules/election-search.js @@ -220,7 +220,7 @@ ElectionSearch.prototype.getUpcomingElections = function() { * Handle a change event on the zip code fields */ ElectionSearch.prototype.handleZipChange = function() { - this.$state.val('').change(); // TODO: jQuery deprecation + this.$state.val('').trigger('change'); this.$district.val(''); }; diff --git a/fec/fec/static/js/modules/filters/date-filter.js b/fec/fec/static/js/modules/filters/date-filter.js index 6b3d3163ed..478fc42ad7 100644 --- a/fec/fec/static/js/modules/filters/date-filter.js +++ b/fec/fec/static/js/modules/filters/date-filter.js @@ -136,8 +136,8 @@ DateFilter.prototype.fromQuery = function(query) { DateFilter.prototype.setValue = function(value) { value = ensureArray(value); - this.$minDate.val(value[0]).change(); // TODO: jQuery deprecation - this.$maxDate.val(value[1]).change(); // TODO: jQuery deprecation + this.$minDate.val(value[0]).trigger('change'); + this.$maxDate.val(value[1]).trigger('change'); }; DateFilter.prototype.handleModifyEvent = function(e, opts) { @@ -146,12 +146,12 @@ DateFilter.prototype.handleModifyEvent = function(e, opts) { if (opts.filterName === this.name) { this.maxYear = parseInt(opts.filterValue); this.minYear = this.maxYear - 1; - this.$minDate.val('01/01/' + this.minYear.toString()).change(); // TODO: jQuery deprecation + this.$minDate.val('01/01/' + this.minYear.toString()).trigger('change'); if (this.maxYear === today.getFullYear()) { today = moment(today).format('MM/DD/YYYY'); - this.$maxDate.val(today).change(); // TODO: jQuery deprecation + this.$maxDate.val(today).trigger('change'); } else { - this.$maxDate.val('12/31/' + this.maxYear.toString()).change(); // TODO: jQuery deprecation + this.$maxDate.val('12/31/' + this.maxYear.toString()).trigger('change'); } this.validate(); } diff --git a/fec/fec/static/js/modules/filters/election-filter.js b/fec/fec/static/js/modules/filters/election-filter.js index 99d2df03e0..a1ead5b6ed 100644 --- a/fec/fec/static/js/modules/filters/election-filter.js +++ b/fec/fec/static/js/modules/filters/election-filter.js @@ -43,7 +43,7 @@ ElectionFilter.prototype.fromQuery = function(query) { this.$cycles .find('input[value="' + cycle + ':' + full + '"]') .prop('checked', true) - .change(); // TODO: jQuery deprecation + .trigger('change'); } return this; }; @@ -80,7 +80,7 @@ ElectionFilter.prototype.handleElectionChange = function(e) { .find('input') .eq(0) .prop('checked', true) - .change(); // TODO: jQuery deprecation + .trigger('change'); }; ElectionFilter.prototype.handleCycleChange = function(e) { @@ -89,9 +89,9 @@ ElectionFilter.prototype.handleCycleChange = function(e) { .split(':'); this.$cycle .val(selected[0]) - .change() // TODO: jQuery deprecation + .trigger('change') .attr('checked', true); - this.$full.val(selected[1]).change(); // TODO: jQuery deprecation + this.$full.val(selected[1]).trigger('change'); this.setTag(); }; diff --git a/fec/fec/static/js/modules/filters/filter-base.js b/fec/fec/static/js/modules/filters/filter-base.js index 4ae6169ff2..1cd852f82f 100644 --- a/fec/fec/static/js/modules/filters/filter-base.js +++ b/fec/fec/static/js/modules/filters/filter-base.js @@ -84,7 +84,7 @@ Filter.prototype.setValue = function(value) { const $input = this.$input.data('temp') ? this.$elm.find('#' + this.$input.data('temp')) : this.$input; - $input.val(prepareValue($input, value)).change(); // TODO: jQuery deprecation + $input.val(prepareValue($input, value)).trigger('change'); return this; }; diff --git a/fec/fec/static/js/modules/filters/filter-typeahead.js b/fec/fec/static/js/modules/filters/filter-typeahead.js index 8827e5fca3..00230f5bd1 100644 --- a/fec/fec/static/js/modules/filters/filter-typeahead.js +++ b/fec/fec/static/js/modules/filters/filter-typeahead.js @@ -276,7 +276,7 @@ FilterTypeahead.prototype.appendCheckbox = function(opts) { } else { const checkbox = $(template_checkbox(data)); checkbox.appendTo(this.$selected); - checkbox.find('input').change(); // TODO: jQuery deprecation + checkbox.find('input').trigger('change'); this.clearInput(); } }; diff --git a/fec/fec/static/js/modules/filters/select-filter.js b/fec/fec/static/js/modules/filters/select-filter.js index 7616cc2182..bb0b2f0ce0 100644 --- a/fec/fec/static/js/modules/filters/select-filter.js +++ b/fec/fec/static/js/modules/filters/select-filter.js @@ -29,7 +29,7 @@ SelectFilter.prototype.fromQuery = function(query) { SelectFilter.prototype.setValue = function(value) { this.$input.find('option[selected]').prop('selected', false); this.$input.find('option[value="' + value + '"]').prop('selected', true); - this.$input.change(); // TODO: jQuery deprecation + this.$input.trigger('change'); }; SelectFilter.prototype.handleChange = function(e) { diff --git a/fec/fec/static/js/modules/filters/text-filter.js b/fec/fec/static/js/modules/filters/text-filter.js index b424cf8b33..ef29d7990f 100644 --- a/fec/fec/static/js/modules/filters/text-filter.js +++ b/fec/fec/static/js/modules/filters/text-filter.js @@ -145,7 +145,7 @@ TextFilter.prototype.appendCheckbox = function(value) { }; const checkbox = $(template_checkbox(opts)); checkbox.appendTo(this.checkboxList.$elm); - checkbox.find('input').change(); + checkbox.find('input').trigger('change'); this.$input.val(''); this.checkboxIndex++; }; diff --git a/fec/fec/static/js/modules/filters/toggle-filter.js b/fec/fec/static/js/modules/filters/toggle-filter.js index cf2cf68577..383d92d364 100644 --- a/fec/fec/static/js/modules/filters/toggle-filter.js +++ b/fec/fec/static/js/modules/filters/toggle-filter.js @@ -16,7 +16,7 @@ ToggleFilter.prototype.fromQuery = function(query) { this.$elm .find('input[value="' + query[this.name] + '"]') .prop('checked', true) - .change(); // TODO: jQuery deprecation + .trigger('change'); }; ToggleFilter.prototype.handleChange = function(e) { diff --git a/fec/fec/static/js/modules/filters/validate-date-filters.js b/fec/fec/static/js/modules/filters/validate-date-filters.js index 0a487be86c..16117e9cda 100644 --- a/fec/fec/static/js/modules/filters/validate-date-filters.js +++ b/fec/fec/static/js/modules/filters/validate-date-filters.js @@ -121,8 +121,8 @@ ValidateDateFilter.prototype.fromQuery = function(query) { ? query['min_' + this.name] : defaultStart; var maxDate = query['max_' + this.name] ? query['max_' + this.name] : now; - this.$minDate.val(minDate).change(); // TODO: jQuery deprecation - this.$maxDate.val(maxDate).change(); // TODO: jQuery deprecation + this.$minDate.val(minDate).trigger('change'); + this.$maxDate.val(maxDate).trigger('change'); return this; }; diff --git a/fec/fec/static/js/modules/tables.js b/fec/fec/static/js/modules/tables.js index 11a28ce216..01fcb4abf6 100644 --- a/fec/fec/static/js/modules/tables.js +++ b/fec/fec/static/js/modules/tables.js @@ -660,7 +660,7 @@ DataTable_FEC.prototype.checkFromQuery = function() { // …if they are not already checked for (let box of queryBoxes) { if (!($(box).is(':checked'))) { - $(box).prop('checked', true).change(); // TODO: jQuery deprecation + $(box).prop('checked', true).trigger('change'); } } $('button.is-loading, label.is-loading').removeClass('is-loading'); @@ -673,7 +673,7 @@ DataTable_FEC.prototype.checkFromQuery = function() { // …if they are not already checked for (let box of queryBoxes) { if (!($(box).is(':checked'))) { - $(box).prop('checked', true).change(); // TODO: jQuery deprecation + $(box).prop('checked', true).trigger('change'); } } } diff --git a/fec/fec/static/js/modules/top-entities.js b/fec/fec/static/js/modules/top-entities.js index 27315fa53e..f079f3d6e5 100644 --- a/fec/fec/static/js/modules/top-entities.js +++ b/fec/fec/static/js/modules/top-entities.js @@ -119,7 +119,7 @@ TopEntities.prototype.updateElectionYearOptions = function(office) { if (currentOption.css('display') == 'none') { $('#election-year') .val(minFutureYear) - .change(); // TODO: jQuery deprecation + .trigger('change'); } } else { // show all options/enable for Safari! diff --git a/fec/fec/tests/js/checkbox-filter.js b/fec/fec/tests/js/checkbox-filter.js index b47a0c5902..9fe800d17a 100644 --- a/fec/fec/tests/js/checkbox-filter.js +++ b/fec/fec/tests/js/checkbox-filter.js @@ -79,19 +79,19 @@ describe('checkbox filters', function() { }); it('sets loaded-once on the input after loading', function() { - this.$input.prop('checked', true).change(); // TODO: jQuery deprecation + this.$input.prop('checked', true).trigger('change'); expect(this.$input.data('loaded-once')).to.be.true; expect(this.$label.attr('class')).to.not.equal('is-loading'); }); it('adds the loading class if it has loaded once', function() { - this.$input.prop('checked', true).change(); // TODO: jQuery deprecation - this.$input.prop('checked', false).change(); // TODO: jQuery deprecation + this.$input.prop('checked', true).trigger('change'); + this.$input.prop('checked', false).trigger('change'); expect(this.$label.attr('class')).to.equal('is-loading'); }); it('triggers the add event on checking a checkbox', function() { - this.$input.prop('checked', true).change(); // TODO: jQuery deprecation + this.$input.prop('checked', true).trigger('change'); expect(this.trigger).to.have.been.calledWith('filter:added', [ { key: 'president', @@ -104,7 +104,7 @@ describe('checkbox filters', function() { }); it('triggers remove event on unchecking a checkbox', function() { - this.$input.prop('checked', false).change(); // TODO: jQuery deprecation + this.$input.prop('checked', false).trigger('change'); expect(this.trigger).to.have.been.calledWith('filter:removed', [ { key: 'president', diff --git a/fec/fec/tests/js/contact-form.js b/fec/fec/tests/js/contact-form.js index 06f0dead59..5daa9ffa52 100644 --- a/fec/fec/tests/js/contact-form.js +++ b/fec/fec/tests/js/contact-form.js @@ -69,12 +69,12 @@ describe('Contact form', function() { }); it('shows the other reason box when other is selected', function() { - this.form.category.val('other').change(); // TODO: jQuery deprecation + this.form.category.val('other').trigger('change'); expect(this.form.otherReason.is(':visible')).to.be.true; }); it('hides the other reason box when another value is selected', function() { - this.form.category.val('option-1').change(); // TODO: jQuery deprecation + this.form.category.val('option-1').trigger('change'); expect(this.form.otherReason.is(':visible')).to.be.false; }); diff --git a/fec/fec/tests/js/cycle-select.js b/fec/fec/tests/js/cycle-select.js index 704010960a..afd774fc0d 100644 --- a/fec/fec/tests/js/cycle-select.js +++ b/fec/fec/tests/js/cycle-select.js @@ -59,7 +59,7 @@ describe('cycle select', function() { }); it('changes the query string on change', function() { - this.cycleSelect.$elm.val('2014').change(); // TODO: jQuery deprecation + this.cycleSelect.$elm.val('2014').trigger('change'); expect(CycleSelect.prototype.setUrl).to.have.been.calledWith(window.location.href + '?cycle=2014'); }); }); @@ -88,7 +88,7 @@ describe('cycle select', function() { }); it('changes the query string on change', function() { - this.cycleSelect.$cycles.find('[name="cycle-toggle-cycle-1"]').val('2014').change(); // TODO: jQuery deprecation + this.cycleSelect.$cycles.find('[name="cycle-toggle-cycle-1"]').val('2014').trigger('change'); expect( CycleSelect.prototype.setUrl ).to.have.been.calledWith( @@ -128,7 +128,7 @@ describe('cycle select', function() { }); it('changes the query string on change', function() { - this.cycleSelect.$elm.val('2014').change(); // TODO: jQuery deprecation + this.cycleSelect.$elm.val('2014').trigger('change'); var url = URI(window.location.href); url.path('2014/'); expect(CycleSelect.prototype.setUrl).to.have.been.calledWith(url.toString()); diff --git a/fec/fec/tests/js/date-filter.js b/fec/fec/tests/js/date-filter.js index 9bb13ebf7c..6d3ca97c12 100644 --- a/fec/fec/tests/js/date-filter.js +++ b/fec/fec/tests/js/date-filter.js @@ -122,7 +122,7 @@ describe('date filter', function() { }); it('triggers an add event with all the right properties', function() { - this.filter.$minDate.val('01/01/2015').change(); // TODO: jQuery deprecation + this.filter.$minDate.val('01/01/2015').trigger('change'); expect(this.trigger).to.have.been.calledWith('filter:added', [ { key: 'min_date', @@ -139,14 +139,14 @@ describe('date filter', function() { it('triggers a remove event if the field has no value', function() { this.filter.$minDate.val('01/01/2015'); - this.filter.$minDate.val('').change(); // TODO: jQuery deprecation + this.filter.$minDate.val('').trigger('change'); expect(this.trigger).to.have.been.calledWith('filter:removed'); }); it('triggers a rename event if the field had a value', function() { this.filter.$minDate.val('01/01/2015'); this.filter.$minDate.data('had-value', true); - this.filter.$minDate.val('02/01/2015').change(); // TODO: jQuery deprecation + this.filter.$minDate.val('02/01/2015').trigger('change'); expect(this.trigger).to.have.been.calledWith('filter:renamed'); expect(this.filter.$minDate.data('loaded-once')).to.be.true; }); diff --git a/fec/fec/tests/js/election-search.js b/fec/fec/tests/js/election-search.js index a40a354d55..0a5e62e3d3 100644 --- a/fec/fec/tests/js/election-search.js +++ b/fec/fec/tests/js/election-search.js @@ -67,22 +67,22 @@ describe('election search', function() { }); it('should disable the district select when state is not set', function() { - this.el.$state.val('').change(); // TODO: jQuery deprecation + this.el.$state.val('').trigger('change'); expect(this.el.$district.prop('disabled')).to.be.true; }); it('should disable the district select when state is set and the state does not have districts', function() { - this.el.$state.val('AS').change(); // TODO: jQuery deprecation + this.el.$state.val('AS').trigger('change'); expect(this.el.$district.prop('disabled')).to.be.true; }); it('should enable the district select when state is set and the state has districts', function() { - this.el.$state.val('VA').change(); // TODO: jQuery deprecation + this.el.$state.val('VA').trigger('change'); expect(this.el.$district.prop('disabled')).to.be.false; }); it('should clear the state select and disable the district select when the zip select is set', function() { - this.el.$zip.val('19041').change(); // TODO: jQuery deprecation + this.el.$zip.val('19041').trigger('change'); expect(this.el.$state.val()).to.equal(''); expect(this.el.$district.prop('disabled')).to.be.true; }); @@ -93,7 +93,7 @@ describe('election search', function() { }); it('should serialize state and district inputs', function() { - this.el.$state.val('VA').change(); // TODO: jQuery deprecation + this.el.$state.val('VA').trigger('change'); this.el.$district.val('01'); expect(this.el.serialize()).to.deep.equal({ cycle: '2016', diff --git a/fec/fec/tests/js/statistical-summary-archive.js b/fec/fec/tests/js/statistical-summary-archive.js index d17f9075d4..bd1ef0487a 100644 --- a/fec/fec/tests/js/statistical-summary-archive.js +++ b/fec/fec/tests/js/statistical-summary-archive.js @@ -83,8 +83,8 @@ describe('Tablefilter', function() { describe('disableNonPresYears', function() { beforeEach(function() { this.disableNonPresYears = spy(Tablefilter.prototype, 'disableNonPresYears'); - this.chooseYear.val('1982').change(); // TODO: jQuery deprecation - this.chooseFiler.val('presidential').change(); // TODO: jQuery deprecation + this.chooseYear.val('1982').trigger('change'); + this.chooseFiler.val('presidential').trigger('change'); this.filter.showTable(); }); diff --git a/fec/fec/tests/js/toggle-filter.js b/fec/fec/tests/js/toggle-filter.js index 066aded68c..35429ace14 100644 --- a/fec/fec/tests/js/toggle-filter.js +++ b/fec/fec/tests/js/toggle-filter.js @@ -60,7 +60,7 @@ describe('toggle filters', function() { }); it('calls handleChange() on change', function() { - this.filter.$elm.find('#efiling').prop('checked', true).change(); // TODO: jQuery deprecation + this.filter.$elm.find('#efiling').prop('checked', true).trigger('change'); expect(this.handleChange).to.have.been.called; }); @@ -94,7 +94,7 @@ describe('toggle filters', function() { }); it('triggers rename event on changing the toggle', function() { - this.$fixture.find('#efiling').prop('checked', true).change(); // TODO: jQuery deprecation + this.$fixture.find('#efiling').prop('checked', true).trigger('change'); expect(this.trigger).to.have.been.calledWith('filter:renamed', [ { key: 'data_type-toggle', diff --git a/fec/fec/tests/js/typeahead-filter.js b/fec/fec/tests/js/typeahead-filter.js index 7879c3d51d..80da7583ac 100644 --- a/fec/fec/tests/js/typeahead-filter.js +++ b/fec/fec/tests/js/typeahead-filter.js @@ -121,10 +121,10 @@ describe('FilterTypeahead', function() { var enableButton = spy(this.FilterTypeahead, 'enableButton'); var disableButton = spy(this.FilterTypeahead, 'disableButton'); - // this.FilterTypeahead.$field.typeahead('val', 'FAKE CANDIDATE').change(); // TODO: jQuery deprecation + // this.FilterTypeahead.$field.typeahead('val', 'FAKE CANDIDATE').trigger('change'); // expect(enableButton).to.have.been.called; - // this.FilterTypeahead.$field.typeahead('val', '').change(); // TODO: jQuery deprecation + // this.FilterTypeahead.$field.typeahead('val', '').trigger('change'); // expect(disableButton).to.have.been.called; // this.FilterTypeahead.enableButton.restore(); From d92c9595870b5c35ad89c16d1dca6504d350eef7 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Thu, 1 May 2025 17:21:29 -0400 Subject: [PATCH 2/2] set prop and trigger change instead of click --- fec/legal/templates/legal-search-results-murs.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fec/legal/templates/legal-search-results-murs.jinja b/fec/legal/templates/legal-search-results-murs.jinja index bf384eff91..4f004f7b17 100644 --- a/fec/legal/templates/legal-search-results-murs.jinja +++ b/fec/legal/templates/legal-search-results-murs.jinja @@ -378,7 +378,7 @@ // ...if they are not already checked for (let box of queryBoxes) { if (!($(box).is(':checked'))) { - $(box).trigger('click'); + $(box).prop('checked', true).trigger('change') } } })();