From 8c35f24431173e716a548db8ee853b619bcef2d8 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 2 Jul 2019 20:00:15 +0100 Subject: [PATCH] rcfilters: Simplify FormWrapperWidget submit code by reducing jQuery use None of this really benefits from the indirection of jQuery objects, CSS selector matching, property accessors. Somewhat follows fa261ed50f3a8c6e. Change-Id: I22ea5216324c6bc9221ce77006430290c79d454f --- .../ui/FormWrapperWidget.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/resources/src/mediawiki.rcfilters/ui/FormWrapperWidget.js b/resources/src/mediawiki.rcfilters/ui/FormWrapperWidget.js index 5d6eaef81d..21e5cad021 100644 --- a/resources/src/mediawiki.rcfilters/ui/FormWrapperWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/FormWrapperWidget.js @@ -67,15 +67,19 @@ FormWrapperWidget.prototype.onLinkClick = function ( e ) { FormWrapperWidget.prototype.onFormSubmit = function ( e ) { var data = {}; - // Collect all data from form - $( e.target ).find( 'input:not([type="hidden"],[type="submit"]), select' ).each( function () { - var value = ''; - - if ( !$( this ).is( '[type="checkbox"]' ) || $( this ).is( ':checked' ) ) { - value = $( this ).val(); + // Collect all data from the form + $( e.target ).find( 'input, select' ).each( function () { + if ( this.type === 'hidden' || this.type === 'submit' ) { + return; } - data[ $( this ).prop( 'name' ) ] = value; + if ( this.type === 'checkbox' && !this.checked ) { + // Use a fixed value for unchecked checkboxes. + data[ this.name ] = ''; + } else { + // Use the live value for select, checked checkboxes, or non-checkbox input. + data[ this.name ] = $( this ).val(); + } } ); this.controller.updateChangesList( data ); -- 2.20.1