Set back focus to the first field in form

This commit is contained in:
Hadi Nategh 2022-05-04 14:19:05 +02:00
parent e4efa38d45
commit 02096632e6
4 changed files with 41 additions and 25 deletions

View File

@ -161,6 +161,8 @@ var et2_htmlarea = /** @class */ (function (_super) {
if (jQuery('#dragover-tinymce').length < 1) if (jQuery('#dragover-tinymce').length < 1)
jQuery("<style id='dragover-tinymce'>.dragover:after {height:calc(100% - " + jQuery(this).height() + "px) !important;}</style>").appendTo('head'); jQuery("<style id='dragover-tinymce'>.dragover:after {height:calc(100% - " + jQuery(this).height() + "px) !important;}</style>").appendTo('head');
}); });
//set back focus to the first field in the form
self.getInstanceManager().focusOnFirstInput();
} }
}); });
}; };

View File

@ -294,6 +294,8 @@ export class et2_htmlarea extends et2_editableWidget implements et2_IResizeable
jQuery(self.editor.iframeElement.contentWindow.document).on('dragenter', function(){ jQuery(self.editor.iframeElement.contentWindow.document).on('dragenter', function(){
if (jQuery('#dragover-tinymce').length < 1) jQuery("<style id='dragover-tinymce'>.dragover:after {height:calc(100% - "+jQuery(this).height()+"px) !important;}</style>").appendTo('head'); if (jQuery('#dragover-tinymce').length < 1) jQuery("<style id='dragover-tinymce'>.dragover:after {height:calc(100% - "+jQuery(this).height()+"px) !important;}</style>").appendTo('head');
}); });
//set back focus to the first field in the form
self.getInstanceManager().focusOnFirstInput();
} }
}); });
} }

View File

@ -483,18 +483,7 @@ var etemplate2 = /** @class */ (function () {
this.resize(); this.resize();
// Automatically set focus to first visible input for popups // Automatically set focus to first visible input for popups
if (this._widgetContainer._egw.is_popup() && jQuery('[autofocus]', this._DOMContainer).focus().length == 0) { if (this._widgetContainer._egw.is_popup() && jQuery('[autofocus]', this._DOMContainer).focus().length == 0) {
var $input = jQuery('input:visible', this._DOMContainer) this.focusOnFirstInput();
// Date fields open the calendar popup on focus
.not('.et2_date')
.filter(function () {
// Skip inputs that are out of tab ordering
var $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();
} }
// Tell others about it // Tell others about it
if (typeof _callback == "function") { if (typeof _callback == "function") {
@ -571,6 +560,21 @@ var etemplate2 = /** @class */ (function () {
this._widgetContainer.setArrayMgrs(this._createArrayManagers(_data)); this._widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
}, this); }, this);
}; };
etemplate2.prototype.focusOnFirstInput = function () {
var $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
var $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 * Check if template contains any dirty (unsaved) content
* *

View File

@ -619,19 +619,7 @@ export class etemplate2
// Automatically set focus to first visible input for popups // Automatically set focus to first visible input for popups
if (this._widgetContainer._egw.is_popup() && jQuery('[autofocus]', this._DOMContainer).focus().length == 0) if (this._widgetContainer._egw.is_popup() && jQuery('[autofocus]', this._DOMContainer).focus().length == 0)
{ {
const $input = jQuery('input:visible', this._DOMContainer) this.focusOnFirstInput();
// 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();
} }
// Tell others about it // Tell others about it
@ -728,6 +716,26 @@ export class etemplate2
}, this); }, this);
} }
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 * Check if template contains any dirty (unsaved) content
* *