From 668ce071fa3332a57e7354768ec588942b4599aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 19 Jul 2018 01:42:09 +0200 Subject: [PATCH] ve.ui.MWTemplateDialog: Prevent focus changes in the setup process This is similar to the hack in ve.ui.MWMetaDialog, except uglier :( We already explicitly focus the right field in the ready process. I am not really sure why the focus change causes the issue, but preventing it definitely fixes it. It would make sense if we changed the value of the field after focussing it (as setValue() restores the validity flag cleared by onFocus()), but we don't seem to do it. Bug: T199838 Change-Id: Ia602551ee0b0885cefbd4cb2fc00d569ff42da67 --- modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js index 6dd7e3438e..605fa5406b 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js @@ -448,7 +448,8 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) { data = data || {}; return ve.ui.MWTemplateDialog.super.prototype.getSetupProcess.call( this, data ) .next( function () { - var template, promise; + var template, promise, + bookletLayout = this.bookletLayout; // Properties this.loaded = false; @@ -462,7 +463,10 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) { } ); // Detach the form while building for performance - this.bookletLayout.$element.detach(); + bookletLayout.$element.detach(); + // HACK: Prevent any setPage() calls (from #onReplacePart) from focussing stuff, it messes + // with OOUI logic for marking fields as invalid (T199838). We set it back to true below. + bookletLayout.autoFocus = false; // Initialization if ( !this.selectedNode ) { @@ -495,9 +499,11 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) { this.loaded = true; this.$element.addClass( 've-ui-mwTemplateDialog-ready' ); - this.$body.append( this.bookletLayout.$element ); + this.$body.append( bookletLayout.$element ); - return promise; + return promise.then( function () { + bookletLayout.autoFocus = true; + } ); }, this ); };