0

Im trying to fix a problem in IE9 with file upload. Im using file upload plugin for JQuery and when I used an input file by default, I have not problem, but if I use an input file hidden and trigger an event by clicking in a button fake, thats dont work.

I'm using two directives to achieve this:

ecm_directives.directive('fileupload', function(){
  return {
   restrict: 'A',
    scope: {
     done: '&',
     progress: '&'
   },
   link: function(scope, element, attrs) {
   var optionsObj = {
    dataType: 'json'
   };

  if (scope.done) {
    optionsObj.done = function(e, data) {
      scope.$apply(function() {
        scope.done({e: e, data: data});
        });
    };
  }

  if (scope.progress) {
    optionsObj.progress = function(e, data) {
      scope.$apply(function() {
        scope.progress({e: e, data: data});
      });
    };
  }

    //the above could easily be done in a loop, to cover
    //all API's that Fileupload provides
    element.fileupload(optionsObj);
  }
 }
});



ecm_directives.directive('uploader', function () {
  return {
    restrict: 'E',
    link: function(scope, element, attrs,ctrl) {
          element.find("button").bind("click", function(){
              element.find(":file").trigger("click").bind("change",function(){
                console.log("change");
                scope.kaka = element.find("input").val();
                scope.$apply();
                console.log("changed",  scope.kaka);
            })
          });
      }
  }
});

And this is the html

<div class="fake-file" ng-show="!candidateFiles.cedula.selected">
      <uploader>
        <button type="button" class="fake-input">
          <span class="placeholder ng-binding"> Seleccione un archivo de su ordenador</span>
        </button>

        <button type="button" class="btn fake-btn fake-upload-btn ng-binding">Subir</button>
        <input ng-model="ccedulaCandidato" id="cedula-file" type="file" name="ccedulaCandidato" data-url="/backend/documents/save/" class="file_upload_btn ng-isolate-scope ng-scope ng-pristine ng-valid" style="display:none" fileupload="" done="uploadFinished(e, data)">
      </uploader>
    </div>

The point is that line: element.find(":file").bind("change",function(){ }

Never enter here in IE9, any idea?

Lorraine
  • 441
  • 5
  • 23

1 Answers1

0

this code won't work in IE9, see IE9 file input triggering using Javascript

element.find(":file").trigger("click")

But if you add console log like this you will see that button click event is working fine.

element.find("button").bind("click", function(){ console.log('I'm in); element.find(":file").trigger("click").bind("change",function(){

Community
  • 1
  • 1
kdlcruz
  • 1,368
  • 13
  • 20