diff --git a/app/common/ValueConverter.ts b/app/common/ValueConverter.ts index 596a6a36..4f422bfd 100644 --- a/app/common/ValueConverter.ts +++ b/app/common/ValueConverter.ts @@ -21,6 +21,8 @@ import {CellValue, GristObjCode} from 'app/plugin/GristData'; * is a list it only converts nicely if the list contains exactly one element. */ export class ValueConverter { + private _isTargetText: boolean = ["Text", "Choice"].includes(this.parser.type); + constructor(public formatter: BaseFormatter, public parser: ValueParser) { } @@ -29,14 +31,15 @@ export class ValueConverter { if (value.length === 1) { // Empty list: ['L'] return null; - } else if (value.length === 2) { + } else if (value.length > 2 || this._isTargetText) { + // List with multiple values, or the target type is text. + // Since we're converting to just one value, + // format the whole thing as text, which is an error for most types. + return this.formatter.formatAny(value); + } else { // Singleton list: ['L', value] // Convert just that one value. value = value[1]; - } else { - // List with multiple values. Since we're converting to just one value, - // format the whole thing as text, which is an error for most types. - return this.formatter.formatAny(value); } } return this.convertInner(value); diff --git a/app/common/ValueFormatter.ts b/app/common/ValueFormatter.ts index 2f9b4efe..5e634826 100644 --- a/app/common/ValueFormatter.ts +++ b/app/common/ValueFormatter.ts @@ -250,7 +250,7 @@ class ReferenceListFormatter extends ReferenceFormatter { // Part of this repeats the logic in BaseFormatter.formatAny which is overridden in ReferenceFormatter // It also ensures that complex lists (e.g. if this RefList is displaying a ChoiceList) // are formatted as JSON instead of CSV. - if (!isList(value) || hasNestedObjects(value)) { + if (!isList(value) || hasNestedObjects(decodeObject(value) as CellValue[])) { return formatUnknown(value); } // In the most common case, lists of simple objects like strings or dates