JavaScript Node-Webkit SaveAs File Dialog only triggers for unique file names? node js saveas

On the Node-Webkit web site (https://github.com/rogerwang/node-webkit/wiki/File-dialogs) it says to use the <Input type="file"> to bring up a file picker dialog, and then listen for the change event to get the path and filename selected or specified.

This works fine the first time when I specify or select a file name, but if I bring up the file picker again and use the SAME file name, the change event doesn't get fired! Only if I change the filename in the selector dialog does the change event fire. Below is an example:

<input id="export_file" type="file" nwsaveas style="display:none" nwworkingdir=""/>
<script>

  var chooser = jQuery("#export_file");

  chooser.change(function(evt) 
  {
     alert(jQuery(this).val());
  });

  chooser.trigger('click'); 

</script>

Does anyone know a way to always fire an event after the user selects a file from the file picker (regardless if the file was previously picked or defined)?

Thanks.

Answer:1

Since your "handler" only gets called when the tag sees a change, you could reset it (after doing your handling -- alert call, in this case) so that every time is like the first time. If you "reset" the input tag, however, that fires a change event, so you need to (1)remove the change event listener, (2)reset the input tag to undefined and (3) restore the change event listener. Using the new node-webkit 0.7.0 File and Filelist constructors -- this will only work with v0.7.0 -- the following code should work.

<script>

  var chooser = jQuery("#export_file");

  function fileHandler (evt) {

    alert(jQuery(this).val());

    var f = new File('',''); 
    var files = new FileList(); 
    files.append(f); 
    chooser.unbind('change'); 
    document.getElementById('export_file').files = files; 
    chooser.change(fileHandler);
  }

  chooser.change(fileHandler);
  chooser.trigger('click'); 

</script>  

Jonathan

"Windows Desktop App Creation with node-webkit"

Answer:2

Without seeing more of your code, I'll hazard a guess and suggest :

jQuery('#export_file').trigger('change');

Hope this helps,

Jonathan

"Windows App Creation with node-webkit"

Answer:3

The ember documentation states that there is a finally handler available on Promises: http://emberjs.com/api/classes/Ember.RSVP.Promise.html#method_finally However, using finally on a promise yields ...

The ember documentation states that there is a finally handler available on Promises: http://emberjs.com/api/classes/Ember.RSVP.Promise.html#method_finally However, using finally on a promise yields ...

In the options page of a chrome extension, localStorage is null and thus can not be used. Here are the files of the unpacked extension producing error. manifest.json { "name": "someTest", "...

In the options page of a chrome extension, localStorage is null and thus can not be used. Here are the files of the unpacked extension producing error. manifest.json { "name": "someTest", "...

I select an element of the page: $mainSection = $('#main'); then I add more Elements via AJAX into the <div id="main"></div> element. Next time I call $mainSection, the newly added ...

I select an element of the page: $mainSection = $('#main'); then I add more Elements via AJAX into the <div id="main"></div> element. Next time I call $mainSection, the newly added ...

  1. prevent element from scrolling
  2. prevent element from losing focus
  3. prevent element from inheriting css
  4. prevent element from getting focus
  5. prevent element from overflowing
  6. prevent element from moving css
  7. prevent element from scrolling css
  8. prevent elements from going to next line
  9. prevent element from being clicked
  10. prevent element from wrapping
  11. prevent element from being tabbed to
  12. prevent element from resizing
  13. prevent element from overlapping
  14. prevent element from drag
  15. prevent element from hover
  16. css prevent element from going off screen
  17. css prevent element from overflowing
  18. prevent flex element from growing
  19. css prevent element from wrapping
  20. html prevent element from getting focus

I have built a website but really struggling with easyslider and Internet explorer. It seems the Javascript is loading and then deciding against it for some reason. jQuery is included in the header ...

I have built a website but really struggling with easyslider and Internet explorer. It seems the Javascript is loading and then deciding against it for some reason. jQuery is included in the header ...