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:
commit
1000fa931c
2 changed files with 25 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue