From eecad5f70f16b1e32d4b199bfaae5cec9e0d5fe3 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 4 May 2022 14:14:48 +0200 Subject: [PATCH] Set back focus to the first field in form --- api/js/etemplate/et2_widget_htmlarea.ts | 2 ++ api/js/etemplate/etemplate2.ts | 37 ++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/api/js/etemplate/et2_widget_htmlarea.ts b/api/js/etemplate/et2_widget_htmlarea.ts index 448bebb1e1..63c6f1cd5e 100644 --- a/api/js/etemplate/et2_widget_htmlarea.ts +++ b/api/js/etemplate/et2_widget_htmlarea.ts @@ -301,6 +301,8 @@ export class et2_htmlarea extends et2_editableWidget implements et2_IResizeable jQuery(self.editor.iframeElement.contentWindow.document).on('dragenter', function(){ if (jQuery('#dragover-tinymce').length < 1) jQuery("").appendTo('head'); }); + //set back focus to the first field in the form + self.getInstanceManager().focusOnFirstInput(); } }); } diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index 02b274ac07..2cd50644bb 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -681,22 +681,7 @@ export class etemplate2 // Automatically set focus to first visible input for popups if(this._widgetContainer._egw.is_popup() && jQuery('[autofocus]', this._DOMContainer).focus().length == 0) { - const $input = jQuery('input:visible', this._DOMContainer) - // Date fields open the calendar popup on focus - .not('.et2_date') - .filter(function() - { - // Skip inputs that are out of tab ordering - const $this = jQuery(this); - return !$this.attr('tabindex') || parseInt($this.attr('tabIndex')) >= 0; - }).first(); - - // mobile device, focus only if the field is empty (usually means new entry) - // should focus always for non-mobile one - if(egwIsMobile() && $input.val() == "" || !egwIsMobile()) - { - $input.focus(); - } + this.focusOnFirstInput(); } // Tell others about it @@ -810,6 +795,26 @@ export class etemplate2 }); } + public focusOnFirstInput() + { + const $input = jQuery('input:visible', this.DOMContainer) + // Date fields open the calendar popup on focus + .not('.et2_date') + .filter(function() + { + // Skip inputs that are out of tab ordering + const $this = jQuery(this); + return !$this.attr('tabindex') || parseInt($this.attr('tabIndex')) >= 0; + }).first(); + + // mobile device, focus only if the field is empty (usually means new entry) + // should focus always for non-mobile one + if(egwIsMobile() && $input.val() == "" || !egwIsMobile()) + { + $input.focus(); + } + } + /** * Check if template contains any dirty (unsaved) content *