Fix clearing of annotation fields

This commit is contained in:
Dan Stillman 2020-12-26 02:33:40 -05:00
parent 69958d4356
commit 6ee3863e37
2 changed files with 12 additions and 1 deletions

View file

@ -746,7 +746,7 @@ Zotero.DataObject.prototype._getChangedField = function (field) {
* Get either the unsaved value of a field or the saved value if unchanged since the last save
*/
Zotero.DataObject.prototype._getLatestField = function (field) {
return this._changedData[field] || this['_' + field];
return this._changedData[field] !== undefined ? this._changedData[field] : this['_' + field];
};
/**

View file

@ -274,5 +274,16 @@ describe("Zotero.Annotations", function() {
assert.deepEqual(annotation[itemProp], exampleImageAlt[prop], `'${prop}' doesn't match`);
}
});
it("should remove empty fields", async function () {
var annotation = await Zotero.Annotations.saveFromJSON(attachment, exampleHighlight);
var json = Object.assign({}, exampleHighlight);
json.comment = '';
json.pageLabel = '';
await Zotero.Annotations.saveFromJSON(attachment, json);
assert.equal(annotation.annotationComment, '');
assert.equal(annotation.annotationPageLabel, '');
});
});
})