Clear item creators when calling setCreators() with an empty array
This commit is contained in:
parent
79748b9132
commit
14341ca16c
2 changed files with 23 additions and 0 deletions
|
@ -1078,6 +1078,14 @@ Zotero.Item.prototype.setCreator = function (orderIndex, data) {
|
||||||
* @param {Object[]} data - An array of creator data in internal or API JSON format
|
* @param {Object[]} data - An array of creator data in internal or API JSON format
|
||||||
*/
|
*/
|
||||||
Zotero.Item.prototype.setCreators = function (data) {
|
Zotero.Item.prototype.setCreators = function (data) {
|
||||||
|
// If empty array, clear all existing creators
|
||||||
|
if (!data.length) {
|
||||||
|
while (this.hasCreatorAt(0)) {
|
||||||
|
this.removeCreator(0);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
this.setCreator(i, data[i]);
|
this.setCreator(i, data[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -435,6 +435,21 @@ describe("Zotero.Item", function () {
|
||||||
item = Zotero.Items.get(id);
|
item = Zotero.Items.get(id);
|
||||||
assert.sameDeepMembers(item.getCreators(), creators);
|
assert.sameDeepMembers(item.getCreators(), creators);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should clear creators if empty array passed", function () {
|
||||||
|
var item = createUnsavedDataObject('item');
|
||||||
|
item.setCreators([
|
||||||
|
{
|
||||||
|
firstName: "First",
|
||||||
|
lastName: "Last",
|
||||||
|
fieldMode: 0,
|
||||||
|
creatorTypeID: 1
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
assert.lengthOf(item.getCreators(), 1);
|
||||||
|
item.setCreators([]);
|
||||||
|
assert.lengthOf(item.getCreators(), 0);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#getAttachments()", function () {
|
describe("#getAttachments()", function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue