Search code examples
cordovabackbone.jsbackbone-viewscordova-pluginscordova-3

cordova app gets refreshed when trying to upload image, using the image picker plugin inside a form


when i try to add images inside a form using the image picker plugin, the app get refreshed. But when i try to add image outside the form it works fine. Can anyone please guide me what am i doing wrong? this is what i have tried

 <form id="formDemand" enctype="multipart/form-data" target="#">
 <div class="row no-gutter">
   <div class="col-lg-12" id="sglUp">
    <button  id="addImgCor">Add Image</button>
    <img id="newimage" src="" style="display:none;width:100%;">
  </div>
 </div>
 </form>

the js script is written in backbone view

addImgCor: function(){
     window.imagePicker.getPictures(
         function(results) {
             for (var i = 0; i < results.length; i++) {
                 console.log('Image URI: ' + results[i]);
             }
         }, function (error) {
             console.log('Error: ' + error);
         }, {
             maximumImagesCount: 10,
             width: 800
         }
     );
     } 

Solution

  • Try to attach type to the button, proper one would be <button type="button">, the default behavior for many browsers is sending the form after hitting the button (for it gets submit as default type).