rcfilters: Simplify FormWrapperWidget submit code by reducing jQuery use
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 2 Jul 2019 19:00:15 +0000 (20:00 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 2 Jul 2019 19:29:17 +0000 (20:29 +0100)
None of this really benefits from the indirection of jQuery objects,
CSS selector matching, property accessors.

Somewhat follows fa261ed50f3a8c6e.

Change-Id: I22ea5216324c6bc9221ce77006430290c79d454f

resources/src/mediawiki.rcfilters/ui/FormWrapperWidget.js

index 5d6eaef..21e5cad 100644 (file)
@@ -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 );