0

When I click on new button then I uploaded the file using lightning file upload now if i'm clicking on cancel button, then I'm again click on new button then the previous uploaded file is there. How can i reset that uploaded file after clicking on cancel button.

Uploading a file

<div class="slds-col slds-size_1-of-1 slds_p_arround ">   
                            <label><span>*</span>Upload Medical Certificate</label>                 
                            <lightning-file-upload name="fileUploader" accept={acceptedFormats} record-id={myRecordId} onuploadfinished={handleUploadFinished}>
                            </lightning-file-upload> {docName}
                        </div>  

Cancel button

<button type="button" class="slds-button slds-button_destructive" onclick={closeSuspendModal}>Cancel</button>

JS

closeSuspendModal()
{
this.isShowSuspendModel=false;   
}

get acceptedFormats() {
        return ['.pdf', '.png', '.docx', '.jpg', '.jpeg'];
    }

    handleUploadFinished(event) {
        // Get the list of uploaded files
        const uploadedFiles = event.detail.files;
        this.docId=uploadedFiles[0].documentId;
        this.docName=uploadedFiles[0].name+' uploaded successfully';
        console.log('1111'+uploadedFiles[0].documentId)
        console.log('1111'+uploadedFiles[0].name)
        
    }
4
  • Hi, and welcome to SFSE! What does your code look like right now? How far have you gotten? Please take a moment to read about How to Ask and take the quick tour, then edit your question to include more information so we can better assist you. – sfdcfox Dec 5 '20 at 14:03
  • Currently on cancelling the button I only close open modal and I want to reset that uploading file if i'm click on cancel button – user90782 Dec 5 '20 at 15:20
  • Again, if you'd share some code, it would be easier to help you. Generally speaking, you can unrender and rerender the modal to reset the fields within. – sfdcfox Dec 5 '20 at 22:56
  • You can check now, i added the code in my question – user90782 Dec 6 '20 at 7:42
0

You'll want to unrender the entire modal, or at least the upload component. For example, you could:

<lightning-file-upload if:true={isShowSuspendModal} name="fileUploader" accept={acceptedFormats} record-id={myRecordId} onuploadfinished={handleUploadFinished}>

This would cause the component to completely unrender when the model is hidden, which should cause the values to reset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.