javascript - How to display selected file name when using the Dropbox API JS Chooser -
i using dropbox chooser (https://www.dropbox.com/developers/dropins/chooser/js) part of form. once user has selected file, display file name next chooser button.
it nice include 'remove' link clear selection.
i assume done using javascript/jquery. appreciated.
edit: earlier answer used e.files[0].link.split('/').pop(), there's field already! it's called name. updated below.
the file name 1 of things returned, can this:
var url = e.files[0].link; var name = e.files[0].name; as how display on page, suggest adding span somewhere , setting text. try code, , couple other nice things (like handle submit button's disabled state , resetting chooser button "unused" state):
<form> <input id="chooser" type="dropbox-chooser" name="selected-file" data-link-type="direct" style="visibility: hidden;"/> <p id="chosen" style="display:none">chosen file: <span id="filename"></span> (<a id="remove" href="#">remove</a>)</p> <input type="submit" id="submit" disabled /> </form> <script> $(function () { $('#chooser').on('dbxchoosersuccess', function (e) { var url = e.originalevent.files[0].link; var filename = e.originalevent.files[0].name; $('#chosen').show(); $('#filename').text(filename); $('#submit').prop('disabled', false); }); $('#remove').click(function (e) { e.preventdefault(); $('#chosen').hide(); $('.dropbox-chooser').removeclass('dropbox-chooser-used'); $('#submit').prop('disabled', true); }); }); </script> edit
i should point out dropbox-chooser-used class noticed. since it's not documented, may change in future version of library. rest should fine.
Comments
Post a Comment