![jQuery]()
File Upload Event
This code uses jQuery to attach an event handler to the change event of the file input with the name “file” within the element with the ID “upload-vehicle-variant-image-modal.” When users select files using the file input, the event handler captures each file’s details (name, size, and a generated ID) and adds them to the filesToUpload
array. After updating the array, the display
function is called to update the UI.
File Removal Event
This code uses event delegation to handle the click event for elements with the class “remove-button.” When a user clicks on the remove button associated with a file, it retrieves the file’s FID (File ID) from the button’s data attribute and removes the corresponding file from the filesToUpload
array. After removal, the display
function is called to update the UI.
Display Function
This function updates the display of uploaded files. It empties the existing file list, iterates through the filesToUpload
array, and appends each file's details to the file list. The details include the file name, size, a remove button, and a thumbnail preview. The file upload count is also updated. The bytesToMB
function is assumed to be defined elsewhere and converts file sizes to megabytes.
Final Code