Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PDFAcroCheckBox.ts #1684

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/form/PDFCheckBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class PDFCheckBox extends PDFField {
*/
isChecked(): boolean {
const onValue = this.acroField.getOnValue();
return !!onValue && onValue === this.acroField.getValue();
return onValue.length > 0 && onValue.includes(this.acroField.getValue());
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/core/acroform/PDFAcroCheckBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class PDFAcroCheckBox extends PDFAcroButton {
};

setValue(value: PDFName) {
const onValue = this.getOnValue() ?? PDFName.of('Yes');
if (value !== onValue && value !== PDFName.of('Off')) {
const onValue = this.getOnValue().length > 0 ? this.getOnValue() : [PDFName.of('Yes')];
if (!onValue.includes(value) && value !== PDFName.of('Off')) {
throw new InvalidAcroFieldValueError();
}

Expand All @@ -40,9 +40,8 @@ class PDFAcroCheckBox extends PDFAcroButton {
return PDFName.of('Off');
}

getOnValue(): PDFName | undefined {
const [widget] = this.getWidgets();
return widget?.getOnValue();
getOnValue(): PDFName[] {
return (this.getWidgets() ?? []).map((widget) => widget.getOnValue());
}
}

Expand Down
Loading