Merge pull request #34625 from hexed0ut/fix-tags-autocomplete

fix(tags): Fix autocomplete to select the best match on Enter
This commit is contained in:
Ejaaz Khan 2025-12-08 11:49:04 +05:30 committed by GitHub
commit 1000fa931c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -99,6 +99,21 @@ frappe.ui.TagEditor = class TagEditor {
$input.trigger("input");
}
});
$input.on("enter-pressed-in-addtag", function (e) {
var value = e.target.value;
frappe.call({
method: "frappe.desk.doctype.tag.tag.get_tags",
args: {
doctype: me.frm.doctype,
txt: value.toLowerCase(),
},
callback: function (r) {
// Updates input to suggestion value (if any) on <enter>
if (r.message.length) $input.val(r.message[0]);
$input.trigger("input-selected");
},
});
});
}
get_args(tag) {
return {

View file

@ -38,10 +38,19 @@ frappe.ui.Tags = class {
};
this.$input.keypress((e) => {
if (e.which == 13 || e.keyCode == 13) select_tag();
if (e.which == 13 || e.keyCode == 13) {
// Triggers event when <enter> is pressed
this.$input.trigger("enter-pressed-in-addtag");
}
});
this.$input.focusout(select_tag);
this.$input.on("input-selected", () => {
// Adds tag if a input is selected
select_tag();
this.deactivate();
});
this.$input.on("blur", () => {
this.deactivate();
});