- if ( $.inArray( false, arguments ) !== -1 ) {
- windowManager.openWindow( 'errorAlert', {
- title: Util.parseMsg( 'apisandbox-submit-invalid-fields-title' ),
- message: Util.parseMsg( 'apisandbox-submit-invalid-fields-message' ),
- actions: [
- {
- action: 'accept',
- label: OO.ui.msg( 'ooui-dialog-process-dismiss' ),
- flags: 'primary'
+ errorCount = countValues( false, arguments );
+ if ( errorCount > 0 ) {
+ actions = [
+ {
+ action: 'accept',
+ label: OO.ui.msg( 'ooui-dialog-process-dismiss' ),
+ flags: 'primary'
+ }
+ ];
+ if ( tokenWidgets.length ) {
+ // Check all token widgets' validity separately
+ deferred = $.when.apply( $, tokenWidgets.map( function ( w ) {
+ return w.apiCheckValid();
+ } ) );
+
+ deferred.done( function () {
+ // If only the tokens are invalid, offer to fix them
+ var tokenErrorCount = countValues( false, arguments );
+ if ( tokenErrorCount === errorCount ) {
+ delete actions[ 0 ].flags;
+ actions.push( {
+ action: 'fix',
+ label: mw.message( 'apisandbox-results-fixtoken' ).text(),
+ flags: 'primary'
+ } );