Ajax attributes data-request-download and data-request-success

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?

Thanks :+1:

Hey Mr @neil-impelling! :slight_smile:

The response is a blob, so it contains no usable data. This is why the success process stops after the file is downloaded.

We could modify it to pass an empty object to the success functions. Using data-request-complete might work too.

Hello Mr. @daft - thanks for getting back to me.

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>

Got it. The success workflow should trigger in v3.6.10 onwards, as expected. Here is the related commit:

1 Like

Legend. Great stuff as always man. Thanks. :sunglasses:

1 Like