Closed wilsonwg closed 7 years ago
You can try to access it via $btn.attr('data-key')
instead of $btn.data('key')
.
I just tried $btn.attr('data-key') but it still returns the same empty value data-key= Maybe something related to scope. Just my guess.
Yes it seems a problem with your calling this code even before the DOM element is initialized... you need to call this code on document.ready
event for example.
Will check if I can enhance this behavior a bit to allow developers to configure a callback for this in an easier way.
I solved the problem!
if I use data-key="{dataKey}"
var btns = '<button type="button" class="kv-cust-btn btn btn-xs btn-default" title="Download" data-key="{dataKey}">' +
'<i class="glyphicon glyphicon-download"></i>' +
'</button>';
Then I get a very strange attribute code: data-key=" data-key="2""="" But I only put {dataKey}
var btns = '<button type="button" class="kv-cust-btn btn btn-xs btn-default" title="Download" {dataKey}>' +
'<i class="glyphicon glyphicon-download"></i>' +
'</button>';
Then it renders the correct html attribute code: data-key="2"
So the example code on the doc page is misleading: http://plugins.krajee.com/file-input#option-otheractionbuttons
Or you may need to change the original codes.
Will correct the docs.
I noticed that the doc got updated, the texts after the template section all appear to be red (after the datakey part). Perhaps you forgot to add a closed tag somewhere. It's a small thing, but kind of annoying when reading the doc.
Fixed.
Great! Thank you!
I am trying to create a download button also. So I added the following to my config
otherActionButtons: '<button type="button" class="kv-cust-btn btn btn-xs btn-default text-muted" title="Download" {dataKey}>' +
'<i class="fa fa-download"></i>' +
'</button>',
The dataKey is replaced as expected initialPreviewConfig.key
... but how can I also pass the download URL? When the use click on the "download" button, I want to download a the file to my local machine.
@CrestApps : You can look my very first post and the very last few lines. You can pass your url into your scripts with the key. Ex: window.location = 'http://...donwload_url_here.../'+key; to initiate the download. This is just one of the possible ways of doing it.
I had been stuck with this problem for months and still can't solve the problem.
I followed the example on the doc page. My codes:
And I always get: data-key=
Is this a bug or something I did wrong?