How to clear the widget state completely after upload

I noticed that whenever I open the widget and upload an image the second time, the image upload twice and if I open the widget the 3rd time and also upload another image, the image uploads thrice. So, I am wondering if there is a way to reset the widget completely or even remove it from the DOM when an image is uploaded.

Hi @noam,

By default, the widget keeps the previously uploaded file, and if you open the widget again, you’ll see the file there. However, if you click the Add button again, it won’t be uploaded again, and the widget’s value won’t be changed. If you select another file, it will be uploaded, and the widget will keep it until you have uploaded another one. If you want to reset the widget after uploading a file, you can set its value to null with JavaScript.

var widget = uploadcare.Widget('[role=uploadcare-uploader]');
widget.onUploadComplete(function() {
  widget.value(null);
});

I’m not quite sure I understand what you meant saying “the image uploads twice.” Can you elaborate?

Thanks, pls check this https://codepen.io/dealwap/pen/QPENdP