How can I sync the page count from Upload-Lift to an option?

The Upload-Lift app supports analyzing document page count via the Convert extension.

With the Extract file info setting enabled on the upload field Convert settings. The JavaScript event for a new file upload will contain the page count in the file.meta.pages field.

To sync the page count to an option inside Live Product Options, you can use the following JavaScript code (update the PAGE_OPTION variable to match your option name):

/* sync page count */
var PAGE_OPTION = "pages"; // TODO change to your option name

window.addEventListener('upload:added', function(e) {
    var file = e.detail;

    if(file.meta?.pages){
        // find on page and set value to number of pages
        var pagesInput = document.querySelector('input[name="properties[' + PAGE_OPTION + ']"]');
        if(pagesInput){
            pagesInput.value = file.meta.pages;
            // trigger input event to update UI
            pagesInput.dispatchEvent(new Event('input', { bubbles: true }));
            // optionally set readonly to prevent user changes
            // pagesInput.readOnly = true;
        }
    }
});

The code can be added in the global App > Settings > Theme Settings > JavaScript section, then it can work across all configurations in the app.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.