0

Context: I have a dynamic number of lightning field upload and i'd like to know from which i'm uploading so i can tag the files to a certain file upload.

visual

and there can be a lot more.

For each file upload has a distinct name so i'd like it to be my id.

here is the code:

 <template for:each={filesList} for:item="item">
            <li class="slds-dropdown__item slds-grid slds-item" key={item.Name}>
                <span class="slds-truncate slds-var-p-horizontal_small slds-col slds-size_1-of-2" title={item}>
                    <template if:true={item.Required}>
                        <abbr class="slds-required" title="required">*</abbr>
                    </template>
                    {item.Name}
                </span>
                <div onclick={getAttribute} id={item.Name}>
                    <lightning-file-upload class="mv-file-upload slds-col slds-size_1-of-2" key={item.Name}
                    label={label.MyVeralti_LabelLinkDoc}
                    name={item.Name}
                    accept={acceptedFormats}
                    record-id={caseId}
                    file-field-name="CodeDocument_fileupload__c"
                    file-field-value={item.DocumentType__c}
                    onuploadfinished={handleUploadFinished}
                    multiple = true>
                    </lightning-file-upload>
                </div>

JS below:

getAttribute(event){
    console.log('insideOnclick: ', event.currentTarget.id);
    this.currentDocumentType = event.currentTarget.id;
}

handleUploadFinished(event) {
    const uploadedFiles = event.detail.files;
    // what is tryied in order to get the context but I couldn't get it also i tryied event.detail.key, name etc... 
    console.log(JSON.parse(JSON.stringify(event.detail)));
    console.log('event.srcEleme: ',JSON.parse(JSON.stringify(event.srcElement)));
    console.log('event.currentTarget: ',JSON.parse(JSON.stringify(event.currentTarget)));
    console.log(JSON.parse(JSON.stringify(event)));
    
    

I didn't succed to get the context (item.Name) from the onuploadfinished so I tried with a div and an 'onclick' so i can get the item.name, stock it and use it onuploadfinished.

I do succeed to get the id from the div but it add some random numbers before each space.

Here is the logs: logs

those number are randoms and never the same.

I have no idea where it come from. So i guess I have two questions:

Why is it doing that? How can I get the context (item.Name) when clicking on a specific file upload?

Thanks in advance.

1 Answer 1

1

So after talking to someone, it apears Salesforce modify the id's on the go.

Also i can use data-id instead of Id

1
  • Correct. HTML breaks in funny ways if there are duplicate ID values in a page, so the framework automatically fixes those ID values so they are unique.
    – sfdcfox
    Feb 23, 2023 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .