1

I use bootstrap image uploader. when i select an image, it show preview. if i want browse another image and i change my mind and i click cancel in browse window, clear previous image too. I want same this with bootstrap uploader.

How can i save previous image when click cancel in browse window? I am early in css and javascript.

narges
  • 681
  • 2
  • 7
  • 26

2 Answers2

1

I found in fileinput.js, in bellow lines:

if (isEmpty(tfiles) || tfiles.length === 0) {
                if (!isAjaxUpload) {
                        self.clear();
                }
                self._showFolderError(folders);
                self._raise('fileselectnone');
                return;
            }

we must comment this line: self.clear();

narges
  • 681
  • 2
  • 7
  • 26
0

Please check the http://jsfiddle.net/ugeshgupta000/LCrE4/18/

 $("#input1").click(function () {
   $(this).val('');
   $('#imagepreview1').prop('src', '');
 });

There is no handler for cancel button. you can make the value empty before clicking on select file option. If user selects some file, it will get new value, otherwise if user clicks on cancel, we have already made the file value null.

Yogesh Kumar Gupta
  • 1,009
  • 1
  • 10
  • 10
  • I don't want to delete previouse image. i want to was same http://jsfiddle.net/isherwood/LCrE4/3/. but i don't know how can do it in bootstrap image uploader that i linked it. – narges Jan 28 '17 at 13:11
  • Even in the fiddle, which you mentioned, clicking cancel doesn't clear out the image preview – Yogesh Kumar Gupta Jan 28 '17 at 13:13
  • Possible duplicate of http://stackoverflow.com/questions/34855400/cancel-event-on-input-type-file You can use onBlur to check if the value is empty or has is got changed – Yogesh Kumar Gupta Jan 28 '17 at 13:19