Santosh Anantharamaiah Santosh Anantharamaiah - 6 months ago 18
jQuery Question

Option for removing the uploaded files displayed using <g:downloadfile> tag

I have used

<g:downloadfile>
tag to display the list of uploaded files. Which will display the uploaded files as the list of downloadable links.

But I have a problem here, I am unable to provide the user, delete option if he/she wish to delete any uploaded file.

Usage:
<g:downloadFiles fileList="${fileList}" />


I think there should be some way out for this using jQuery or javaScript.

Thanks in advance for the help.

Answer

Below is the solution which I have written for my question:

GSP:

<g:each in="${fileList}" var="file">
    <div class="remove">
        <a href="#">
            <span class="glyphicon glyphicon-remove"></span></a>
        <a href="/forms/landing/attachment/${file.attachmentId}" filename="${file.name}">${file.name}</a>
        </br>
    </div>
</g:each>

jQuery:

$(document).ready(function(){
    $('.glyphicon-remove').click ( function(e){
        e.preventDefault();
        $(this).parent().parent().remove();
    });
});