@@ -301,7 +301,11 @@ var WmdUploadDialog = function (opts) {
301301 this . _makeLinkMarkdown = opts . makeLinkMarkdown ;
302302
303303 this . setFileType ( opts . dialogType === 'file' ? 'attachment' : 'image' ) ;
304- this . setInputId ( util . makeId ( 'file-upload' ) ) ;
304+ // Counter ensures each dialog instance gets a unique file-input ID.
305+ // Never decremented: monotonic growth guarantees no ID collisions,
306+ // even if the modal:after-close DOM cleanup hasn't fired yet.
307+ WmdUploadDialog . _counter += 1 ;
308+ this . setInputId ( util . makeId ( 'file-upload-' + WmdUploadDialog . _counter ) ) ;
305309 this . _headerEnabled = true ;
306310 this . setHeadingText ( opts . headingText ) ;
307311
@@ -310,6 +314,7 @@ var WmdUploadDialog = function (opts) {
310314 }
311315} ;
312316inherits ( WmdUploadDialog , FileUploadDialog ) ;
317+ WmdUploadDialog . _counter = 0 ;
313318
314319WmdUploadDialog . prototype . createDom = function ( ) {
315320 var me = this ;
@@ -326,6 +331,10 @@ WmdUploadDialog.prototype.createDom = function () {
326331
327332 WmdUploadDialog . superClass_ . createDom . call ( this ) ;
328333
334+ this . _element . on ( 'modal:after-close' , function ( ) {
335+ me . _element . remove ( ) ;
336+ } ) ;
337+
329338 // Override reject handler to also notify makeLinkMarkdown.
330339 // Must rebind the button because super createDom() already bound the original.
331340 var originalReject = me . _reject_handler ;
0 commit comments