(core) Fixing bug on a fresh Choice and ChoiceList column

Summary: Adding a new element to a new Choice or ChoiceList column resulted in javascript error

Test Plan: Browser tests

Reviewers: georgegevoian, dsagal

Reviewed By: georgegevoian, dsagal

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D2932
pull/9/head
Jarosław Sadziński 3 years ago
parent f5981606e1
commit 9cc034f606

@ -80,7 +80,7 @@ ChoiceEditor.prototype.prepForSave = async function() {
const selectedItem = this.autocomplete && this.autocomplete.getSelectedItem();
if (selectedItem && selectedItem.isNew) {
const choices = this.options.field.widgetOptionsJson.prop('choices');
await choices.saveOnly([...choices.peek(), selectedItem.label]);
await choices.saveOnly([...(choices.peek() || []), selectedItem.label]);
}
}

@ -157,7 +157,7 @@ export class ChoiceListEditor extends NewBaseEditor {
const newChoices = tokens.filter(t => t.isNew).map(t => t.label);
if (newChoices.length > 0) {
const choices = this.options.field.widgetOptionsJson.prop('choices');
await choices.saveOnly([...choices.peek(), ...new Set(newChoices)]);
await choices.saveOnly([...(choices.peek() || []), ...new Set(newChoices)]);
}
}

Loading…
Cancel
Save