ApiSandbox: Don't use OO.ui.NumberInputWidget for limit fields
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 14 Nov 2016 16:52:16 +0000 (11:52 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 14 Nov 2016 17:05:30 +0000 (12:05 -0500)
According to T150455#2789277 it shouldn't be able to allow 'max' even
though this is a mostly-numeric field with one non-numeric value.
Oh well.

Change-Id: I620a233aab20c715db354eff77ea8a3ffee3bc77

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

index 64cfcf5..9364e07 100644 (file)
                                        break;
 
                                case 'limit':
-                                       widget = new OO.ui.NumberInputWidget( {
-                                               required: Util.apiBool( pi.required ),
-                                               isInteger: true
+                                       widget = new OO.ui.TextInputWidget( {
+                                               required: Util.apiBool( pi.required )
                                        } );
-                                       widget.setIcon = widget.input.setIcon.bind( widget.input );
-                                       widget.setIconTitle = widget.input.setIconTitle.bind( widget.input );
-                                       widget.getValidity = widget.input.getValidity.bind( widget.input );
-                                       widget.input.setValidation( function ( value ) {
-                                               return value === 'max' || widget.validateNumber( value );
+                                       widget.setValidation( function ( value ) {
+                                               var n, pi = this.paramInfo;
+
+                                               if ( value === 'max' ) {
+                                                       return true;
+                                               } else {
+                                                       n = +value;
+                                                       return !isNaN( n ) && isFinite( n ) &&
+                                                               /* jshint bitwise: false */
+                                                               ( n | 0 ) === n &&
+                                                               /* jshint bitwise: true */
+                                                               n >= pi.min && n <= pi.apiSandboxMax;
+                                               }
                                        } );
+                                       pi.min = pi.min || 0;
+                                       pi.apiSandboxMax = mw.config.get( 'apihighlimits' ) ? pi.highmax : pi.max;
                                        widget.paramInfo = pi;
                                        $.extend( widget, WidgetMethods.textInputWidget );
-                                       widget.setRange( pi.min || 0, mw.config.get( 'apihighlimits' ) ? pi.highmax : pi.max );
                                        multiMode = 'enter';
                                        break;