MChan
MChan

Reputation: 7162

Meteor sending click to input file

I am trying to trigger clicking an input file element inside a template once a specific link is clicked, though nothing happens when I click on the link, can someone please tell me what I am missing here / doing wrong? Thanks

Template.uploadResources.events({
'click #drop1link':function(event, template){
     $(event.target).find('[name=upl]').click();
 }
});

Template:

<template name="uploadResources">
           <div class="col-md-4">
            <form id="upload-2" method="post" enctype="multipart/form-data" class="upload">
                <div id="drop-2" class="drop">
                    <a id="drop1link" name="drop1link">Click Here</a>
                    <input type="file" name="upl" multiple />
                </div>
            </form>
            </div>            
</template>

Upvotes: 0

Views: 244

Answers (2)

Ramsay Lanier
Ramsay Lanier

Reputation: 426

Its not working because you are using .find() but what you are looking for is not a descendant of the event.target. You could use .next(), like so.

Template.uploadResources.events({
'click #drop1link':function(event, template){
     $(event.target).next('[name=upl]').click();
 }
});

Upvotes: 1

Aaron
Aaron

Reputation: 141

try using the trigger() function to fire the event like so: $(event.target).find('[name=upl]').trigger('click');

Upvotes: 1

Related Questions