nick
December 20, 2021, 4:24pm
1
Product: WebViewer
Product Version: 8.3.0-20211201
Please give a brief summary of your issue:
We’re displaying a custom error message in loadDocument
's onError
callback, i.e.
webViewer.Core.documentViewer.loadDocument(documentMeta.source, {
onError(error) {
// ...
webViewer.UI.showErrorMessage('Unable to preview file.');
}
});
Is there a way to clear this error message when loading a subsequent document given a single instantiation of WebViewer? Should the error message automatically be cleared when webViewer.UI.closeDocument()
is invoked?
Hello,
You can close the modal with instance.UI.closeElements
: PDFTron WebViewer Namespace: UI . Here is a guide on it as well: https://www.pdftron.com/documentation/web/guides/hiding-elements/#opening-closing-elements-programmatically .
Currently, the error modal component is not hooked up to close when the document viewer triggers an unload event. This is likely since there were a few cases when the error needs to be up once the document is closed. You can listen for the documentUnloaded event (PDFTron WebViewer Class: DocumentViewer ) yourself and close the modal when the closeDocument
API is called.
Andy Huang
nick
December 20, 2021, 8:16pm
3
Thanks.
This doesn’t seem to work immediately in the close context (i.e. the dialog is still visible when the next document loads):
webViewer.UI.closeDocument();
webViewer.UI.closeElements(['errorModal']);
Does the UI need to be additionally refreshed?
Hm, I am not sure how you are using the code but it seems to work fine when I am testing.
In my testing, I first handle closing the modal on documentUnload
:
instance.docViewer.addEventListener('documentUnloaded', () => {
instance.UI.closeElements(['errorModal']);
});
I have a preloaded document but I call showErrorMessage
shortly after to make the modal appear.
instance.UI.showErrorMessage('Unable to preview file.');
I then use closeDocument
to close the document and I reload another document. The modal does not reappear or stay on the viewer after doing so.
Are there specific steps you are taking? Does it only occur for you if you use onError
?
nick
December 20, 2021, 10:33pm
5
Does it only occur for you if you use onError
?
Yes, this issue does seemed to be scoped to the onError
callback context, i.e.
load a problematic document that results in an error (i.e. source URL 400s)
load another document (the error modal remains visible)
load another document (the error modal clears)
Hm, I don’t seem to be able to reproduce this. The onError
doesn’t seem to trigger on my end. Perhaps you could try listening to this instead? https://www.pdftron.com/documentation/web/guides/wv-events/#document-load-error-handling
Otherwise, I might need the file you were testing with or sample where the issue is reproducible.