pekebyte / pekeUpload

jQuery html5 file uploader plugin
http://pekebyte.github.io/pekeUpload
Other
82 stars 73 forks source link

Add pekeUpload dynamically #10

Closed ivanblue closed 9 years ago

ivanblue commented 11 years ago

Hello, I want to add pekeUpload widgets dynamically but when I do the widget fail to work. How can I achieve this?

This is my code:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">

        <title>PekeUpload Test</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">

        <link href="/css/bootstrap.css" rel="stylesheet">
        <link href="/css/bootstrap-responsive.css" rel="stylesheet">

    </head>
    <body>
        <div id="uploadwidgets">
            <p>
                <input type="file" id="uploadfield1" name="uploadfield1" class="fileuploadtest" />
            </p>

            <p>
                <input type="file" id="uploadfield2" name="uploadfield2" class="fileuploadtest" />
            </p>
        </div>
        <button id="btnAddUploadWidget">Add upload widget</button>

        <script type="text/javascript" src="/js//jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="/js/pekeUpload-master/js/pekeUpload.min.js"></script>

        <script type="text/javascript">
            $(function(){
                $("#uploadwidgets").append("<input type=\"file\" id=\"uploadfield3\" name=\"uploadfield3\" class=\"fileuploadtest\" />");

                $(".fileuploadtest").pekeUpload({
                    theme: "bootstrap",
                    url: "pekeupload2.php",
                });

                $(document).on("click", "#btnAddUploadWidget", function(){

                    $("#uploadwidgets").append("<p><input type=\"file\" id=\"uploadfield3\" name=\"uploadfield3\" class=\"fileuploadtest\" /></p>");
                });
            });
        </script>
    </body>
</html>

Creating a new pekeUpload with the add button is the one that fails. Thanks

mwq27 commented 10 years ago

Have you tried moving:

$(".fileuploadtest").pekeUpload({
                theme: "bootstrap",
                url: "pekeupload2.php",
            });

into your click event, right after the .append()?