Fix crash if item field invalid for new type is open on type change

https://forums.zotero.org/discussion/71200/bug-when-changing-item-type-report-id-607330517
This commit is contained in:
Dan Stillman 2018-04-01 15:34:44 -04:00
parent 8d0dc359b4
commit a8d199967e

View File

@ -1087,12 +1087,17 @@
<method name="changeTypeTo"> <method name="changeTypeTo">
<parameter name="itemTypeID"/> <parameter name="itemTypeID"/>
<parameter name="menu"/> <parameter name="menu"/>
<body> <body><![CDATA[
<![CDATA[ return (async function () {
if (itemTypeID == this.item.itemTypeID) { if (itemTypeID == this.item.itemTypeID) {
return true; return true;
} }
if (this.saveOnEdit) {
await this.blurOpenField();
await this.item.saveTx();
}
var fieldsToDelete = this.item.getFieldsNotInType(itemTypeID, true); var fieldsToDelete = this.item.getFieldsNotInType(itemTypeID, true);
// Special cases handled below // Special cases handled below
@ -1149,15 +1154,15 @@
if (this.saveOnEdit) { if (this.saveOnEdit) {
// See note in transformText() // See note in transformText()
this.blurOpenField().then(() => this.item.saveTx()); await this.blurOpenField();
await this.item.saveTx();
} }
else { else {
this.refresh(); this.refresh();
} }
if (this.eventHandlers['itemtypechange'] && this.eventHandlers['itemtypechange'].length) { if (this.eventHandlers['itemtypechange'] && this.eventHandlers['itemtypechange'].length) {
var self = this; this.eventHandlers['itemtypechange'].forEach(f => f.bind(this)());
this.eventHandlers['itemtypechange'].forEach(function (f) f.bind(self)());
} }
return true; return true;
@ -1169,8 +1174,8 @@
} }
return false; return false;
]]> }.bind(this))();
</body> ]]></body>
</method> </method>