0

My Durandal app uploads files. I've just added a fallback mode for ie8 that doesn't use File. Instead, I create an iframe and append it to document.body, then set its innerHTML to create a form. I move the <input type='file' name='file' id='file' /> to the form in the iframe and submit the form.

This works and the file duly arrives at the server where my handler saves it to disk and generates a response containing the file size.

I have a handler attached to the iframe load event and it fires and obtains the file size.

But after that my Ui behaves as though all event handlers are unbound.

Does anyone recognise these symptoms?

I've noticed that

  • If I do all the above but don't submit the form my UI is unaffected.
  • If I put app.showMessage("load handler"); in the load handler, it runs but the dialog fails to appear and the UI is catatonic
  • If I also put app.showMessage("pre-submit"); immediately prior to submitting the form, I see the load handler message, then the pre-submit message, and the UI is responsive

More information

This is the innerHTML of the iframe document's body, formatted for your convenience but otherwise unaltered.

<form action="ClassicUploadHandler.aspx" enctype="multipart/form-data" method="post">
  <input name="fileID" value="9845ee66-e1e6-4c1c-8305-965a3ccc16ed">
  <input name="file" id="file" style="display: none;" 
         type="file" data-bind="event: {change: chose}">
</form>

Note that the transplanted file input still has a knockout data-bind element. Is it possible that this is the source of an unhandled exception? Durandal is notorious (with me, at any rate) for going catatonic whenever there's an unhandled exception.

If this is the source of the problem then the solution is to un-bind it prior to transplant. Is that possible, and if so how?

Peter Wone
  • 17,965
  • 12
  • 82
  • 134
  • Is this happening when you are in dev mode or in production? I have seen a similar issue happen with dev tools opened on certain browsers but I don't think it is a Durandal issue. – PW Kad Mar 27 '14 at 01:11
  • It's dev and since posting the question I've accidentally figured it out: asp.net is putting
     around my plain text text/plain output and this is causing an unhandled exception. For some reason I don't know, Durandal seems to go catatonic on unhandled exceptions. May just be my installation, who knows.
    – Peter Wone Mar 27 '14 at 03:49
  • Hmm, it seems the original problem is also real. – Peter Wone Mar 27 '14 at 04:30

1 Answers1

1

Peter, is it possible that ko.cleanNode() will do what you want?

Unbind view model from view in knockout suggests this approach.

Community
  • 1
  • 1
DavidRa
  • 188
  • 8
  • I cannot find this method in the knockout documentation so I figured what the hell and just tried it using the syntax described in the answer you reference. Congratulations, I pegged the problem and you saved the day. – Peter Wone Mar 28 '14 at 02:13