"apisandbox-dynamic-error-exists": "A parameter named \"$1\" already exists.",
"apisandbox-deprecated-parameters": "Deprecated parameters",
"apisandbox-fetch-token": "Auto-fill the token",
+ "apisandbox-add-multi": "Add",
"apisandbox-submit-invalid-fields-title": "Some fields are invalid",
"apisandbox-submit-invalid-fields-message": "Please correct the marked fields and try again.",
"apisandbox-results": "Results",
"apisandbox-dynamic-error-exists": "Displayed as an error message from JavaScript when trying to add a new arbitrary parameter with a name that already exists. Parameters:\n* $1 - Parameter name that failed.",
"apisandbox-deprecated-parameters": "JavaScript button label and fieldset legend for separating deprecated parameters in the UI.",
"apisandbox-fetch-token": "Label for the button that fetches a CSRF token.",
+ "apisandbox-add-multi": "Label for the button to add another value to a field that accepts multiple values",
"apisandbox-submit-invalid-fields-title": "Title for a JavaScript error message when fields are invalid.",
"apisandbox-submit-invalid-fields-message": "Content for a JavaScript error message when fields are invalid.",
"apisandbox-results": "JavaScript tab label for the tab displaying the API query results.\n{{Identical|Result}}",
* @return {OO.ui.Widget}
*/
createWidgetForParameter: function ( pi, opts ) {
- var widget, innerWidget, finalWidget, items, $button, $content, func,
- multiMode = 'none';
+ var widget, innerWidget, finalWidget, items, $content, func,
+ multiModeButton = null,
+ multiModeInput = null,
+ multiModeAllowed = false;
opts = opts || {};
$.extend( widget, WidgetMethods.textInputWidget );
$.extend( widget, WidgetMethods.passwordWidget );
widget.setValidation( Validators.generic );
- multiMode = 'enter';
+ multiModeAllowed = true;
+ multiModeInput = widget;
break;
case 'integer':
if ( Util.apiBool( pi.enforcerange ) ) {
widget.setRange( pi.min || -Infinity, pi.max || Infinity );
}
- multiMode = 'enter';
+ multiModeAllowed = true;
+ multiModeInput = widget;
break;
case 'limit':
pi.apiSandboxMax = mw.config.get( 'apihighlimits' ) ? pi.highmax : pi.max;
widget.paramInfo = pi;
$.extend( widget, WidgetMethods.textInputWidget );
- multiMode = 'enter';
+ multiModeAllowed = true;
+ multiModeInput = widget;
break;
case 'timestamp':
widget.paramInfo = pi;
$.extend( widget, WidgetMethods.textInputWidget );
$.extend( widget, WidgetMethods.dateTimeInputWidget );
- multiMode = 'indicator';
+ multiModeAllowed = true;
break;
case 'upload':
break;
}
- if ( Util.apiBool( pi.multi ) && multiMode !== 'none' ) {
+ if ( Util.apiBool( pi.multi ) && multiModeAllowed ) {
innerWidget = widget;
- switch ( multiMode ) {
- case 'enter':
- $content = innerWidget.$element;
- break;
-
- case 'indicator':
- $button = innerWidget.$indicator;
- $button.css( 'cursor', 'pointer' );
- $button.attr( 'tabindex', 0 );
- $button.parent().append( $button );
- innerWidget.setIndicator( 'next' );
- $content = innerWidget.$element;
- break;
-
- default:
- throw new Error( 'Unknown multiMode "' + multiMode + '"' );
- }
+
+ multiModeButton = new OO.ui.ButtonWidget( {
+ label: mw.message( 'apisandbox-add-multi' ).text()
+ } );
+ $content = innerWidget.$element.add( multiModeButton.$element );
widget = new OO.ui.PopupTagMultiselectWidget( {
allowArbitrary: true,
return false;
}
};
- switch ( multiMode ) {
- case 'enter':
- innerWidget.connect( null, { enter: func } );
- break;
-
- case 'indicator':
- $button.on( {
- click: func,
- keypress: function ( e ) {
- if ( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) {
- func();
- }
- }
- } );
- break;
+
+ if ( multiModeInput ) {
+ multiModeInput.on( 'enter', func );
}
+ multiModeButton.on( 'click', func );
}
if ( Util.apiBool( pi.required ) || opts.nooptional ) {