Skip to content

Commit

Permalink
Show warning if forms are present in the PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
photown committed Dec 27, 2023
1 parent 928337e commit d344951
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/FormInputValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ export class FormInputValues {
public readonly optionNameToSelectedIndex: Map<string, number> = new Map();
public readonly radioGroupNameToSelectedIndex: Map<string, number> =
new Map();

public isEmpty(): boolean {
return (
this.textNameToValue.size == 0 &&
this.checkboxNameToValue.size == 0 &&
this.dropdownNameToSelectedIndex.size == 0 &&
this.optionNameToSelectedIndex.size == 0 &&
this.radioGroupNameToSelectedIndex.size == 0
);
}
}
3 changes: 2 additions & 1 deletion src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ function onPageLoad() {
view.setOnPdfFileChosenListener(
function () {
const overlays: Overlays = extractOverlays();
const formValues = view.extractFormInputValues();
return (
overlays.pagesOverlays.size == 0 ||
(overlays.pagesOverlays.size == 0 && formValues.isEmpty()) ||
confirm(
"If you load another PDF, all changes in the current PDF will be lost. Are you sure?"
)
Expand Down

0 comments on commit d344951

Please sign in to comment.