Fix ApiSandbox
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 10 Nov 2016 17:18:19 +0000 (12:18 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 10 Nov 2016 17:39:33 +0000 (12:39 -0500)
I2b8ef74e broke it by removing the isValid() method from
TextInputWidget.

Bug: T150454
Change-Id: Iae48c6e038ce66d294a1bf5f6852e29540ac208c

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

index 98ed3ee..a206328 100644 (file)
                        },
                        apiCheckValid: function () {
                                var that = this;
-                               return this.isValid().done( function ( ok ) {
+                               return this.getValidity().then( function () {
+                                       return $.Deferred().resolve( true ).promise();
+                               }, function () {
+                                       return $.Deferred().resolve( false ).promise();
+                               } ).done( function ( ok ) {
                                        ok = ok || suppressErrors;
                                        that.setIcon( ok ? null : 'alert' );
                                        that.setIconTitle( ok ? '' : mw.message( 'apisandbox-alert-field' ).plain() );
                },
 
                dateTimeInputWidget: {
-                       isValid: function () {
-                               var ok = !Util.apiBool( this.paramInfo.required ) || this.getApiValue() !== '';
-                               return $.Deferred().resolve( ok ).promise();
+                       getValidity: function () {
+                               if ( !Util.apiBool( this.paramInfo.required ) || this.getApiValue() !== '' ) {
+                                       return $.Deferred().resolve().promise();
+                               } else {
+                                       return $.Deferred().reject().promise();
+                               }
                        }
                },
 
                                        } );
                                        widget.setIcon = widget.input.setIcon.bind( widget.input );
                                        widget.setIconTitle = widget.input.setIconTitle.bind( widget.input );
-                                       widget.isValid = widget.input.isValid.bind( widget.input );
+                                       widget.getValidity = widget.input.getValidity.bind( widget.input );
                                        widget.paramInfo = pi;
                                        $.extend( widget, WidgetMethods.textInputWidget );
                                        if ( Util.apiBool( pi.enforcerange ) ) {
                                        } );
                                        widget.setIcon = widget.input.setIcon.bind( widget.input );
                                        widget.setIconTitle = widget.input.setIconTitle.bind( widget.input );
-                                       widget.isValid = widget.input.isValid.bind( widget.input );
+                                       widget.getValidity = widget.input.getValidity.bind( widget.input );
                                        widget.input.setValidation( function ( value ) {
                                                return value === 'max' || widget.validateNumber( value );
                                        } );