Enhance handleReset functionality and fix async issues
Updated the `handleReset` method in `app.js` to await the `Swal.fire` call, ensuring proper asynchronous handling. Added logic to reset editable text form fields and restore widget backgrounds after signing. Refactored `app.min.js` to align with changes in `app.js`, ensuring consistency between the minified and non-minified versions. Improved code readability and maintainability across both files.
This commit is contained in:
@@ -354,7 +354,7 @@ class App {
|
||||
}
|
||||
|
||||
async handleReset(event) {
|
||||
const result = Swal.fire({
|
||||
const result = await Swal.fire({
|
||||
title: localized.resetConfirmTitle,
|
||||
text: localized.resetConfirmText,
|
||||
icon: 'question',
|
||||
@@ -362,7 +362,24 @@ class App {
|
||||
})
|
||||
|
||||
if (result.isConfirmed) {
|
||||
const result = await deleteAnnotations(this.pdfKit)
|
||||
await deleteAnnotations(this.pdfKit)
|
||||
|
||||
// Reset editable text form field values (Position, City)
|
||||
const allFormFields = await this.pdfKit.getFormFields()
|
||||
const editableFields = allFormFields.filter(f =>
|
||||
f instanceof PSPDFKit.FormFields.TextFormField && !f.readOnly
|
||||
)
|
||||
for (const field of editableFields) {
|
||||
await this.pdfKit.setFormFieldValues({ [field.name]: '' })
|
||||
}
|
||||
|
||||
// Restore widget backgrounds that were made transparent after signing
|
||||
for (const w of this.signatureWidgets) {
|
||||
const pageAnnots = await this.pdfKit.getAnnotations(w.pageIndex)
|
||||
const widgetAnnot = pageAnnots.find(a => a.id === w.id)
|
||||
if (widgetAnnot)
|
||||
await this.pdfKit.update(widgetAnnot.set('backgroundColor', null))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user