Fix broken creator autocomplete if place becomes a base field

Well this was a wild one to debug.

Creator fields were only initialized for autocomplete due to a series of
>10-year-old bugs:

1) In `showEditor()`, `Zotero.ItemFields.isAutocompleteField(fieldName)`
   was called for creator fields, which would pass, e.g.,
   `creator-0-lastName`.

2) In `isAutocompleteField()`, `ItemFields.getName()` would normalize
   `creator-0-lastName` to `false`, since it's not a valid field.

3) `isAutocompleteField()` listed `place` as a base field despite its
   not having any mapped fields, so when `getTypeFieldsFromBase()` was
   called on it, the return value would be `false`, which would be added
   to the list of autocomplete fields, which would mean that the
   normalized field of `false` from `creator-0-lastName` would match,
   which would mean that `isAutocompleteField('creator-0-lastName')`
   would always return true...as long as `place` never gained a mapped
   field.

Except `isAutocompleteField()` wasn't supposed to be the test for
initializing autocomplete for creator fields anyway -- `fieldName ==
'creator'` was. But `fieldName` is something like `creator-0-lastName`,
not `creator`, which meant that that test always failed, which meant
that if `place` did gain a mapped field, both tests would fail, which
would cause the creator field not to be initialized for autocomplete,
which would cause it to break as soon as you started to type into it.

This fixes that.
This commit is contained in:
Dan Stillman 2023-01-09 05:28:58 -05:00
parent 9d2c7d44f8
commit ff38ff5b9d
2 changed files with 7 additions and 4 deletions

View file

@ -1584,8 +1584,7 @@
}
else {
// Add auto-complete for certain fields
if (Zotero.ItemFields.isAutocompleteField(fieldName)
|| fieldName == 'creator') {
if (field == 'creator' || Zotero.ItemFields.isAutocompleteField(fieldName)) {
t.setAttribute('type', 'autocomplete');
t.setAttribute('autocompletesearch', 'zotero');

View file

@ -347,7 +347,11 @@ Zotero.ItemFields = new function() {
this.isAutocompleteField = function (field) {
field = this.getName(field);
var fieldName = this.getName(field);
if (!fieldName) {
Zotero.logError(`Can't check autocomplete for invalid field '${field}'`);
return false;
}
var autoCompleteFields = [
'journalAbbreviation',
@ -377,7 +381,7 @@ Zotero.ItemFields = new function() {
autoCompleteFields = autoCompleteFields.concat(add);
}
return autoCompleteFields.indexOf(field) != -1;
return autoCompleteFields.includes(fieldName);
}