From: Timo Tijhof Date: Tue, 2 Jul 2019 19:00:15 +0000 (+0100) Subject: rcfilters: Simplify FormWrapperWidget submit code by reducing jQuery use X-Git-Tag: 1.34.0-rc.0~1180^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=8c35f24431173e716a548db8ee853b619bcef2d8;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 );