Merge pull request #12568 from calixteman/defaultvalue

[api-minor] JS -- Add default value in annotation data
This commit is contained in:
Tim van der Meij 2020-11-05 22:53:21 +01:00 committed by GitHub
commit 646f895d35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -951,6 +951,13 @@ class WidgetAnnotation extends Annotation {
}); });
data.fieldValue = this._decodeFormValue(fieldValue); data.fieldValue = this._decodeFormValue(fieldValue);
const defaultFieldValue = getInheritableProperty({
dict,
key: "DV",
getArray: true,
});
data.defaultFieldValue = this._decodeFormValue(defaultFieldValue);
data.alternativeText = stringToPDFString(dict.get("TU") || ""); data.alternativeText = stringToPDFString(dict.get("TU") || "");
data.defaultAppearance = data.defaultAppearance =
getInheritableProperty({ dict, key: "DA" }) || getInheritableProperty({ dict, key: "DA" }) ||
@ -1652,6 +1659,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
return { return {
id: this.data.id, id: this.data.id,
value: this.data.fieldValue, value: this.data.fieldValue,
defaultValue: this.data.defaultFieldValue,
multiline: this.data.multiLine, multiline: this.data.multiLine,
password: this.hasFieldFlag(AnnotationFieldFlag.PASSWORD), password: this.hasFieldFlag(AnnotationFieldFlag.PASSWORD),
charLimit: this.data.maxLen, charLimit: this.data.maxLen,
@ -1976,6 +1984,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
return { return {
id: this.data.id, id: this.data.id,
value, value,
defaultValue: this.data.defaultFieldValue,
editable: !this.data.readOnly, editable: !this.data.readOnly,
name: this.data.fieldName, name: this.data.fieldName,
rect: this.data.rect, rect: this.data.rect,
@ -2052,6 +2061,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
return { return {
id: this.data.id, id: this.data.id,
value, value,
defaultValue: this.data.defaultFieldValue,
editable: !this.data.readOnly, editable: !this.data.readOnly,
name: this.data.fieldName, name: this.data.fieldName,
rect: this.data.rect, rect: this.data.rect,

View File

@ -1421,6 +1421,8 @@ describe("annotation", function () {
}); });
it("should handle unknown text alignment, maximum length and flags", function (done) { it("should handle unknown text alignment, maximum length and flags", function (done) {
textWidgetDict.set("DV", "foo");
const textWidgetRef = Ref.get(124, 0); const textWidgetRef = Ref.get(124, 0);
const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]); const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]);
@ -1437,6 +1439,7 @@ describe("annotation", function () {
expect(data.hidden).toEqual(false); expect(data.hidden).toEqual(false);
expect(data.multiLine).toEqual(false); expect(data.multiLine).toEqual(false);
expect(data.comb).toEqual(false); expect(data.comb).toEqual(false);
expect(data.defaultFieldValue).toEqual("foo");
done(); done();
}, done.fail); }, done.fail);
}); });
@ -2021,6 +2024,7 @@ describe("annotation", function () {
it("should handle checkboxes with export value", function (done) { it("should handle checkboxes with export value", function (done) {
buttonWidgetDict.set("V", Name.get("1")); buttonWidgetDict.set("V", Name.get("1"));
buttonWidgetDict.set("DV", Name.get("2"));
const appearanceStatesDict = new Dict(); const appearanceStatesDict = new Dict();
const normalAppearanceDict = new Dict(); const normalAppearanceDict = new Dict();
@ -2044,6 +2048,7 @@ describe("annotation", function () {
expect(data.annotationType).toEqual(AnnotationType.WIDGET); expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true); expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual("1"); expect(data.fieldValue).toEqual("1");
expect(data.defaultFieldValue).toEqual("2");
expect(data.radioButton).toEqual(false); expect(data.radioButton).toEqual(false);
expect(data.exportValue).toEqual("Checked"); expect(data.exportValue).toEqual("Checked");
done(); done();
@ -2052,6 +2057,7 @@ describe("annotation", function () {
it("should handle checkboxes without export value", function (done) { it("should handle checkboxes without export value", function (done) {
buttonWidgetDict.set("V", Name.get("1")); buttonWidgetDict.set("V", Name.get("1"));
buttonWidgetDict.set("DV", Name.get("2"));
const buttonWidgetRef = Ref.get(124, 0); const buttonWidgetRef = Ref.get(124, 0);
const xref = new XRefMock([ const xref = new XRefMock([
@ -2067,6 +2073,7 @@ describe("annotation", function () {
expect(data.annotationType).toEqual(AnnotationType.WIDGET); expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true); expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual("1"); expect(data.fieldValue).toEqual("1");
expect(data.defaultFieldValue).toEqual("2");
expect(data.radioButton).toEqual(false); expect(data.radioButton).toEqual(false);
done(); done();
}, done.fail); }, done.fail);
@ -2074,6 +2081,7 @@ describe("annotation", function () {
it("should handle checkboxes without /Off appearance", function (done) { it("should handle checkboxes without /Off appearance", function (done) {
buttonWidgetDict.set("V", Name.get("1")); buttonWidgetDict.set("V", Name.get("1"));
buttonWidgetDict.set("DV", Name.get("2"));
const appearanceStatesDict = new Dict(); const appearanceStatesDict = new Dict();
const normalAppearanceDict = new Dict(); const normalAppearanceDict = new Dict();
@ -2096,6 +2104,7 @@ describe("annotation", function () {
expect(data.annotationType).toEqual(AnnotationType.WIDGET); expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true); expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual("1"); expect(data.fieldValue).toEqual("1");
expect(data.defaultFieldValue).toEqual("2");
expect(data.radioButton).toEqual(false); expect(data.radioButton).toEqual(false);
expect(data.exportValue).toEqual("Checked"); expect(data.exportValue).toEqual("Checked");
done(); done();
@ -3093,6 +3102,7 @@ describe("annotation", function () {
choiceWidgetDict.set("Opt", [encodedString]); choiceWidgetDict.set("Opt", [encodedString]);
choiceWidgetDict.set("V", encodedString); choiceWidgetDict.set("V", encodedString);
choiceWidgetDict.set("DV", Name.get("foo"));
const choiceWidgetRef = Ref.get(984, 0); const choiceWidgetRef = Ref.get(984, 0);
const xref = new XRefMock([ const xref = new XRefMock([
@ -3107,6 +3117,7 @@ describe("annotation", function () {
).then(({ data }) => { ).then(({ data }) => {
expect(data.annotationType).toEqual(AnnotationType.WIDGET); expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldValue).toEqual([decodedString]); expect(data.fieldValue).toEqual([decodedString]);
expect(data.defaultFieldValue).toEqual("foo");
expect(data.options).toEqual([ expect(data.options).toEqual([
{ exportValue: decodedString, displayValue: decodedString }, { exportValue: decodedString, displayValue: decodedString },
]); ]);