My use case, is that I have a modal that captures some users details before giving them a PDF download.
Once they get the file, i’d like to close that modal and reset the form.
Seems that data-request-success is never triggered when using with data-request-download. Is this by design? Am I missing something? And is there an alternative to use when using data-request-download?
I did try with data-request-complete. The problem I had with this is that it’s triggered when there’s a ValidationException thrown too.
For now, I’ve got a javascript function that checks whether the returned data is an instance of Blob. I can use this to decide whether to close the modal or not.
<form id="download_form"
data-request="onDownload"
data-request-validate
data-request-download
data-request-complete="closeModal(data)">
<label for="download_email_input">Email Address</label>
<input id="download_email_input" type="email" name="email">
<p data-validate-for="email"></p>
<button type="submit">Download</button>
</form>
<script>
function closeModal(data) {
if (data instanceof Blob) {
// Reset Form
document.getElementById('download_form').reset();
// close modal with javascript
}
}
</script>