fix: focus on first input only if needed (#22212)

This commit is contained in:
Sagar Vora 2023-08-28 13:45:32 +05:30 committed by GitHub
parent 07ff74edc5
commit e71c5142cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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() {