Fix tags not being saved in item tags box when pressing Enter

SyntaxError: Element.querySelector: '[ztabindex=1]' is not a valid selector

https://forums.zotero.org/discussion/106405/zotero-7-changes-to-item-tag-do-not-persist
This commit is contained in:
Dan Stillman 2023-07-25 05:50:17 -04:00
parent fb59345637
commit 630c6d0d97
2 changed files with 42 additions and 1 deletions

View file

@ -902,7 +902,7 @@
Zotero.debug('Looking for tabindex ' + nextIndex, 4);
var next = this.querySelector(`[ztabindex=${nextIndex}]`);
var next = this.querySelector(`[ztabindex="${nextIndex}"]`);
if (next.length) {
next = next[0];
next.click();

View file

@ -14,6 +14,47 @@ describe("Item Tags Box", function () {
win.close();
});
describe("Tag Editing", function () {
it("should update tag when pressing Enter in textbox", async function () {
var tag = Zotero.Utilities.randomString();
var newTag = Zotero.Utilities.randomString();
var tabbox = doc.getElementById('zotero-view-tabbox');
tabbox.selectedIndex = 0;
var item = await createDataObject('item', { tags: [{ tag }] });
tabbox = doc.getElementById('zotero-view-tabbox');
tabbox.selectedIndex = 2;
var tagsbox = doc.querySelector('tags-box');
var rows = tagsbox.querySelectorAll('li');
assert.equal(rows.length, 1);
assert.equal(rows[0].textContent, tag);
var label = rows[0].querySelector('label[fieldname="tag"]');
label.click();
var input = rows[0].querySelector('input[fieldname="tag"]');
input.value = newTag;
// Press Enter in textbox
var enterEvent = new KeyboardEvent('keydown', {
'key': 'Enter',
'code': 'Enter',
'keyCode': 13,
'which': 13
});
input.dispatchEvent(enterEvent);
await waitForItemEvent('modify');
rows = tagsbox.querySelectorAll('li');
assert.equal(rows[0].textContent, newTag);
// Should open new empty textbox
assert.equal(rows.length, 2);
});
});
describe("#notify()", function () {
it("should update an existing tag on rename", function* () {
var tag = Zotero.Utilities.randomString();