question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Addfile fires before hidden input is populated by file-encode plugin

See original GitHub issue

Hi! Awesome work on this plugin, I love it šŸ˜„

I’m trying to dynamically render the preview image (using the base64 string) outside of the plugin. In order to achieve this, I’m trying to get the base64 string as soon as it’s ready so I can update my preview. However, it seems like the FilePond:addfile event fires before the hidden input is created (let alone ready) and FilePond:processfile doesn’t seem to fire at all…?

How can I access the information in the hidden input when a file is added? Is there a special event for when the file-encode plugin is ready?

My attempt:

FilePond.registerPlugin(FilePondPluginFileEncode);

// original input[type=file]
var input = document.querySelector('input');

// upgrade file input to filepond
FilePond.create(input);

var pond = document.querySelector('.filepond--root');

pond.addEventListener('FilePond:addfile', function() {
    // Element doesn't exist yet
    console.log('No element: ', pond.querySelector('input[name="filepond"]'));
   
    setTimeout(function () {
      // Now the element exists and the value is accessible
      console.log('Value: ', pond.querySelector('input[name="filepond"]'));
    }, 5000);
});

pond.addEventListener('FilePond:processfile', function(event) {
    // Doesn't seem to fire at all?
    console.log('Nothing..', event);
});

https://codepen.io/RijkvanZanten/full/QmJLZv

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

2reactions
DamSenVietcommented, Apr 12, 2018

@rijkvanzanten For now as a temporary solution, here’s what I did to detect whether the encoding is finished. I’m just polling every 300ms. To a user it should be imperceptible and seems to work. Let’s assume you’re submitting a form. The following code should work.

var encodedChecker = null; //global namespace
function beginUpload() {
    // only one repeating interval should exist at any time for uploading (assuming you only want to upload one file) 
    if (encodedChecker !== null) {
        clearInterval(encodedChecker); // perfectly safe to clear null, but we don't need to do that.
        encodedChecker = null; // just to be safe
    }

    // set encodedChecker to the interval id
    encodedChecker = setInterval(function() {
        console.log('polling...');

        // if value is there
        if ($('input[name="filepond"]')[0].value !== "") {
            callbackfunction(); // start actual upload
            clearInterval(encodedChecker);
        }
    }, 300);
};


If you’re not using a form to submit, you may need to check for whether the hidden element exists before calling the starting the interval!

1reaction
rikschenninkcommented, Apr 12, 2018

@rijkvanzanten @DamSenViet Just published version 1.2.11 of FilePond and 1.0.4 of the File Encode plugin. Should fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FilePond Documentation - PQINA
A plugin will fire a FilePond:pluginloaded event on the document when it's ready for use. ... FilePond stores unique id 12345 in a...
Read more >
Filepond Receive Undefined Value In Hidden Input - ADocLib
Tells FilePond to store files in hidden file input elements so they can be Set to ... Addfile fires before hidden input is...
Read more >
Assign file as value of hidden input - javascript - Stack Overflow
I have tried various ways to implement the method described above ( assign each separate file to the value of an input[type="hidden"] field...
Read more >
Overriding/replacing hidden field value - WordPress.org
I am populating the field with the ā€œdefault_cbā€ parameter which worked perfectly on the first run but of course only fires when there...
Read more >
How can I confirm that a hidden form field is populating?
Open the Forms page in Google Chrome from a company IP address. Ā· Open Chrome Web Tools (View > Developer > Developer Tools)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found