diff --git a/src/core/annotation.js b/src/core/annotation.js index 1da946338..5133633c0 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -1610,11 +1610,14 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation { } } - // Determine the field value. In this case, it may be a string or an - // array of strings. For convenience in the display layer, convert the - // string to an array of one string as well. - if (!Array.isArray(this.data.fieldValue)) { + // The field value can be `null` if no item is selected, a string if one + // item is selected or an array of strings if multiple items are selected. + // For consistency in the API and convenience in the display layer, we + // always make the field value an array with zero, one or multiple items. + if (isString(this.data.fieldValue)) { this.data.fieldValue = [this.data.fieldValue]; + } else if (!this.data.fieldValue) { + this.data.fieldValue = []; } // Process field flags for the display layer. diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index aaba14975..9964cb676 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -2479,8 +2479,8 @@ describe("annotation", function () { }); it("should convert the field value to an array", function (done) { - const inputs = ["Foo", ["Foo", "Bar"]]; - const outputs = [["Foo"], ["Foo", "Bar"]]; + const inputs = [null, "Foo", ["Foo", "Bar"]]; + const outputs = [[], ["Foo"], ["Foo", "Bar"]]; let promise = Promise.resolve(); for (let i = 0, ii = inputs.length; i < ii; i++) {