meteor-autoform-file icon indicating copy to clipboard operation
meteor-autoform-file copied to clipboard

Custom "Choose file" button not working

Open tab00 opened this issue 9 years ago • 2 comments

When using a custom template for the "Choose file" button by creating a template as in the ReadMe example:

<template name="mySelectFileBtn">
  <button type="button" class="js-af-select-file">Upload file</button>
</template>

and setting selectFileBtnTemplate: 'mySelectFileBtn' in the schema, the button renders correctly. However a file dialog does not appear when clicked.

When I inspected the original "Choose file" HTML code, there is an input tag of type "file" in the button. So I tried to do the same in the custom template:

<template name="mySelectFileBtn">
  <button type="button" class="js-af-select-file">Upload file
<input type="file" class="js-file">
</button>
</template>

This opens the file dialog when clicked, however after choosing a file there is no result, nor is there any error message.

I should add that element input should not be nested inside element button, as that is invalid HTML.

Please fix the problem(s).

tab00 avatar Jan 28 '16 09:01 tab00

Try this: https://github.com/yogiben/meteor-autoform-file/issues/85#issuecomment-177516681

isbjorn avatar Jan 31 '16 15:01 isbjorn

There's one more bit of code that's missing from the custom upload button example and it is activating the jQuery file upload plugin. In addition to what @isbjorn suggest, I had to add that bit:

Template.mySelectFileBtn.onRendered(function () {
  this.$(".js-file").fileupload();
});

The built-in button has that code here, which won't be executed with a custom template.

diegonc avatar Apr 21 '16 00:04 diegonc