ApiSandbox: Fix upload widget
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 26 Jul 2019 15:03:24 +0000 (11:03 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 26 Jul 2019 15:03:24 +0000 (11:03 -0400)
Attempting to send the request with an active upload widget was
producing a JavaScript error "TypeError: this.setIcon is not a
function". This was probably broken by Iaaa226ea.

Further, validation was not working correctly since getValue() was
returning undefined rather than null as documented. This was probably
broken by I8d736fbb.

Bug: T229123
Change-Id: I78a6f9f0cffcd229ec0ab80c2309a0ee2089c927

resources/src/mediawiki.special.apisandbox/apisandbox.js

index 395fb8b..c2c5960 100644 (file)
                                // Can't, sorry.
                        },
                        apiCheckValid: function () {
-                               var ok = this.getValue() !== null || suppressErrors;
-                               this.setIcon( ok ? null : 'alert' );
+                               var ok = this.getValue() !== null && this.getValue() !== undefined || suppressErrors;
+                               this.info.setIcon( ok ? null : 'alert' );
                                this.setTitle( ok ? '' : mw.message( 'apisandbox-alert-field' ).plain() );
                                return $.Deferred().resolve( ok ).promise();
                        }