Personalizing the fileTemplate selection in FineUploader

My English is not the best, so apologies in advance. I'm struggling to customize the FineUploader FileTemplate option. I don't want to use fineUploaderBasic; I want total customization. Initially, I managed to hide the file name and size after a successful upload. However, customizing the delete button has proven to be an issue. After the upload, the delete button appears but remains disabled, making it impossible to click. Below is my code:

var restricteduploader = new qq.FineUploader({
                        element: $('#restricted-fine-uploader')[0],
                        text: {
                            uploadButton: '<div><i class="icon-upload icon-white"></i>Subir Imagen</div>',
                            deleteButton: '<input type="button" id="btnDelete" value="Eliminar imagen" />'
                        },

                        template:
                        '<div class="qq-uploader">' +
                            '<div class="qq-upload-drop-area"><span>{dragZoneText}</span></div>' +
                            '<div class="qq-upload-button">{uploadButtonText}</div>' +
                            '<span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>' +
                            '<ul class="qq-upload-list"></ul>' +
                        '</div>',
                        fileTemplate:
                            '<li>' +
                                '<div class="qq-progress-bar"></div>' +
                                '<span class="qq-upload-spinner"></span>' +
                                '<span class="qq-upload-finished"></span>' +
                                '<span class="qq-edit-filename-icon"></span>' +
                                '<span class="hide-file"></span>' +
                                '<div>IMAGEN SUBIDA CON EXITO!!</div>' +
                                '<input class="qq-edit-filename" tabindex="0" type="text">' +
                                '<span class="hide-size"></span>' +
                                '<a class="qq-upload-cancel" href="#">{cancelButtonText}</a>' +
                                '<a class="qq-upload-retry" href="#">{retryButtonText}</a>' +
                                '<div class="qq-upload-delete">{deleteButtonText}</div>' +
                                '<span class="qq-upload-status-text">{statusText}</span>' +
                            '</li>',
                        classes: {
                            file: 'hide-file',
                            size: 'hide-size'
                        },
                        request: {
                            endpoint: '<%= Url.Action("UploadBatchDataFile", "Account") %>'
                        },
                        deleteFile: {
                            enabled: true,
                            endpoint: '<%= Url.Action("DeleteFile", "Account") %>',
                            method: 'POST'
                        },
                        multiple: false,
                    validation: {
                        allowedExtensions: ['jpeg', 'jpg', 'png'],
                        sizeLimit: 411062 // 50 kB = 50 * 1024 bytes
                    },
                    showMessage: function (message) {
                        $('#restricted-fine-uploader').append('<div class="alert-error">' + message + '</div>');
                    },
                    messages: { typeError : "{file} no es un tipo de imagen valido. Imagenes valida(s): {extensions}." },
                    callbacks: {
                        onSubmitDelete: function(event, id) {
                            var filename = $(this).fineUploader('getName', id);
                            $(this).fineUploader('setDeleteFileParams', {filename: filename}, id);
                        },
                        onComplete: function (id, filename, responseJSON) {
                            if (responseJSON.success) {
                                $('div div.alert-error').remove();

                                $('#imgUploaded').attr("src", "<%: Url.Content("~/Images/") %>" + responseJSON.filename);
                                $('#hidImage').attr("value", "<%: Url.Content("~/Images/") %>" + responseJSON.filename);

                            }
                        }
                    }
                });

I find customizing the fileTemplate challenging. Previously, I attempted to integrate the FileTemplate into a table by modifying the template as follows:

'<ul class="qq-upload-list"></ul>' to '<table class="qq-upload-list"></table>'

and adjusting the fileTemplate like this:

'<li>' to '<tr><td>' and '</li>' to </td></tr>

Unfortunately, these changes didn't result in the desired outcome. Following a successful upload, FineUploader failed to display the FileTemplate.

Answer №1

Initially, in the onComplete handler, there is a syntax error that needs to be corrected. Update

$('#imgUploaded').attr("src", "<%: Url.Content("~/Images/") %>" + responseJSON.filename);
$('#hidImage').attr("value", "<%: Url.Content("~/Images/") %>" + responseJSON.filename); 

to

$('#imgUploaded').attr("src", "<%: Url.Content('~/Images/') %>" + responseJSON.filename);
$('#hidImage').attr("value", "<%: Url.Content('~/Images/') %>" + responseJSON.filename);

Next, within the text option properties, ensure you are providing text instead of HTML for button labels. Adjust

text: {
    uploadButton: '<div><i class="icon-upload icon-white"></i>Subir Imagen</div>',
    deleteButton: '<input type="button" id="btnDelete" value="Eliminar imagen" />'
},

to

text: {
    uploadButton: 'Subir Imagen',
    deleteButton: 'Eliminar imagen'
},

If customization like adding an upload icon is desired, modify the template option properties:

template:
    '<div class="qq-uploader">' +
        '<div class="qq-upload-drop-area"><span>{dragZoneText}</span></div>' +
        '<div class="qq-upload-button"><i class="icon-upload icon-white"></i>{uploadButtonText}</div>' +
        '<span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>' +
        '<ul class="qq-upload-list"></ul>' +
        '</div>',

Lastly, ensure consistency by using jQuery throughout your FineUploader instance. Consider leveraging the FineUploader jQuery plugin for improved functionality and ease of use:

$("#restricted-fine-uploader").fineUploader({
    // .. define your options here, same as above ...
}).on('submitDelete', function (event, id) {
    var filename = $(this).fineUploader('getName', id);
    $(this).fineUploader('setDeleteFileParams', {filename: filename}, id);

}).on('complete', function (event, id, filename, responseJSON) {
    if (responseJSON.success) {
        $('div div.alert-error').remove();

        $('#imgUploaded').attr("src", "<%: Url.Content('~/Images/') %>" + responseJSON.filename);
        $('#hidImage').attr("value", "<%: Url.Content('~/Images/') %>" + responseJSON.filename);

    }
});

Refer to this documentation for utilizing the jQuery plugin

Update

Below is additional code illustrating proper usage of the jQuery plugin with events and incorporating an input element for the delete button.

Note: Requires FineUploader version 3.7.1 or higher

JavaScript

$(function () {
    $("#restricted-fine-uploader").fineUploader({
        text: {
            uploadButton: "<i class='icon-upload icon-white'></i>Subir Imagen"
        },
        fileTemplate:
            '<li>' +
            '<div class="qq-progress-bar"></div>' +
            '<span class="qq-upload-spinner"></span>' +
            '<span class="qq-upload-finished"></span>' +
            '<span class="hide-file"></span>' +
            '<div>IMAGEN SUBIDA CON EXITO!!</div>' +
            '<span class="hide-size"></span>' +
            '<a class="qq-upload-cancel" href="#">{cancelButtonText}</a>' +
            '<a class="qq-upload-retry" href="#">{retryButtonText}</a>' +
            '<input class="qq-upload-delete" type="button" value="{deleteButtonText}" />' +
            '<span class="qq-upload-status-text">{statusText}</span>' +
            '</li>',

        classes: {
            file: 'hide-file',
            size: 'hide-size'
        },
        request: {
            endpoint: '<%= Url.Action("UploadBatchDataFile", "Account") %>'
        },
        deleteFile: {
            enabled: true,
            endpoint: '<%= Url.Action("DeleteFile", "Account") %>',
            method: 'POST'
        },
        multiple: false,
        validation: {
            allowedExtensions: ['jpeg', 'jpg', 'png'],
            sizeLimit: 411062 // 50 kB = 50 * 1024 bytes
        },
        showMessage: function (message) {
            $('#restricted-fine-uploader').append('<div class="alert-error">' + message + '</div>');
        },
        messages: {
            typeError: "{file} no es un tipo de imagen valido. Imagenes valida(s): {extensions}."
        }
    }).on('submitDelete', function (event, id) {
        var filename = $(this).fineUploader('getName', id);
        $(this).fineUploader('setDeleteFileParams', {
            filename: filename
        }, id);
    }).on('complete', function (id, filename, responseJSON) {
        if (responseJSON.success) {
            $('div div.alert-error').remove();

            $('#imgUploaded').attr('src', '<%: Url.Content("~/Images/") %>' + responseJSON.filename);
            $('#hidImage').attr('value', '<%: Url.Content("~/Images/") %>' + responseJSON.filename);

        }
    });
});

HTML

<ul id="restricted-fine-uploader"></ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it best to stick with a static page size, or

While I typically design my webpages dynamically by determining the screen size and creating divs accordingly, I'm curious about the advantages of using a 'static' sizing approach (such as using pixels). Any insights on this contrasting meth ...

Access a webpage whose URL has been dynamically assigned using JavaScript

I have a website that consists of a single page and features four tabs. Whenever a tab is clicked, it displays the corresponding content in a div while hiding the other three divs along with their respective content. To ensure a smooth user experience, I u ...

Could Google Adsense be causing issues with my website's navigation bar?

There seems to be an irritating bug that I've come across. While navigating my website, [the menu (located in the top right corner) functions correctly]. However, when you land on a page with a Google AdSense ad, the menu suddenly appears distorted ...

Tailwind - make sure the dropdown list is always on top of all other elements

Having an issue configuring the position of a dropdown list. The objective is to ensure it stays on top of all elements, however, when inside a relative positioned element, it ends up being obscured by it. Here's an example code snippet to illustrate ...

Utilizing multiple address parameters within a single-page application

Apologies for the lengthy post. I have encountered an issue with my code after running it through a bot that I can't seem to resolve. In my code, I aim to create functionality where you can visit the address #two, followed by two separate parameters ...

Saving Style Sheets in a Database

Currently, I am interested in saving CSS data in a mySql database as part of my LAMP setup. My intention is to create an input field that includes the following code: body{ background: url("http://google.com/image.jpg") no-repeat; color: orange; } #someDi ...

Windows and MacOS each use unique methods for displaying linear gradients

Check out this code snippet featuring a background gradient background: rgba(0,0,0,0) linear-gradient(rgb(245, 245, 245),rgba(0,0,0,0)) repeat scroll 0 0; This code renders correctly on Windows (chrome, ie, firefox) https://i.stack.imgur.com/XU2gW ...

What is the process for modifying information within a text document?

What I am trying to achieve is a ticker with two buttons that can increment or decrement the value by one each time they are clicked. In addition, I want this value to be synced with a number stored in a text file. For instance, if both the counter and t ...

What is the best way to apply focus to a list element using Javascript?

I recently created code to display a list of elements on my webpage. Additionally, I implemented JavaScript functionality to slice the elements. Initially, my page displays 5 elements and each time a user clicks on the "show more" link, an additional 5 ele ...

Divide the page vertically. On the left side, feature an eye-catching image, while on the right side,

While I have a good understanding of bootstrap 5, I am currently working on a project that requires me to split the page down the center. However, I also need to incorporate a container in the middle that sets a boundary for the text so it doesn't exp ...

Excess gap detected in dual-column design

Exploring HTML once again, I'm currently working on creating a 2 column layout that doesn't rely on floats in order to maintain the natural document flow. Most solutions I've come across involve floats or tables, which I want to avoid. I als ...

Getting rid of all CSS properties currently set for the Mobile view

Utilizing third-party library components in my project. The library includes components that come with predefined styles for mobile devices. I am seeking to completely UPDATE these properties within my own code. When I say "update," I mean removing all th ...

Expanding the width of three floating divs in the center to match the width of the parent container div

In my design, I have a parent container with three inner divs that are floated. The left and right divs have fixed sizes, however, I need the center div to expand and fill the space available within the parent container. <div class="parent-container"&g ...

Confirm if the username is present in jQuery PHP

I am currently working on a functionality to verify if a username is already registered in my application using jQuery, Ajax, and POST method. HTML <div class="form-group"> <label for="username" class="col-md-3 control-label">Username< ...

Modify the database value linked to an <input> element each time its value is modified

I attempted to create something similar to the example provided here $(document).ready(function(){ $('input[type=text]').keyup(function(){ var c=0; var a=$(this).attr('name'); //a is string //if var a change.. ...

Enable Class exclusively on upward scrolling on the browser

Is there a way to dynamically change the class of an element only when the user scrolls the browser page upwards? Issue Filide>> JavaScript $(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll <= 100) { $( ...

Can IE(7?) cause distortion of backgrounds from sprites?

This task is giving me a headache. We're almost finished with revamping our website. The last step involves consolidating all the glyphs and icons into a sprite. These images are transparent .png files, so we made sure the sprite maintains transparen ...

Generate a list item that is contenteditable and includes a button for deletion placed beside it

I am attempting to create a ul, where each li is set as contenteditable and has a delete button positioned to the left of that li. My initial attempt looked like this: <ul id='list'> <li type='disc' id='li1' cl ...

Animating back with a jQuery if statement

Is there a way to implement an if statement that triggers an animation when the right image reaches +400px, and then animates back to -400px upon hovering over the image? $('#left img').mouseenter(function() { $('#right img').animate ...

Looking for CSS templates for improving your business web apps?

Many CSS templates out there are fixed-width, typically around 900 pixels wide... Right now, I'm in the process of creating an intranet Rails application and I'm seeking a good resource for CSS templates designed specifically for business applic ...