From e71c5142cf7f9757002b494f6329bd2ad41d5d73 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Mon, 28 Aug 2023 13:45:32 +0530 Subject: [PATCH] fix: focus on first input only if needed (#22212) --- frappe/public/js/frappe/form/form.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 30ba5eaad9..ec690e7a41 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -647,10 +647,18 @@ frappe.ui.form.Form = class FrappeForm { } focus_on_first_input() { - let first = this.form_wrapper.find(".form-layout :input:visible:first"); - if (!in_list(["Date", "Datetime"], first.attr("data-fieldtype"))) { - first.focus(); + const layout_wrapper = this.layout.wrapper; + + // dont do anything if the current active element is inside the form + // user must have clicked on some element before this function trigerred + if (!layout_wrapper || layout_wrapper.has(":focus").length) { + return; } + + layout_wrapper + .find(":input:visible:first") + .not("[data-fieldtype^='Date']") + .trigger("focus"); } run_after_load_hook() {