0

In my mvc application I have used one bootstrap popup, I need to check whether any changes are made in textboxes in this popup before closing this window, and give an option to save this before closing. How can I handle the close event of bootstrap popup window? I have tried

$('#myModal').on('hidden.bs.modal', function () {
    // do something…
})

It will only fire after the close event.

tmg
  • 18,757
  • 5
  • 67
  • 73
Jiju John
  • 783
  • 3
  • 11
  • 33
  • 1
    Look at [Bind a function to Twitter Bootstrap Modal Close](http://stackoverflow.com/questions/8363802/bind-a-function-to-twitter-bootstrap-modal-close) – Himanshu Raval Jun 06 '16 at 13:38
  • attach a mutation observer to the modal form fields and trigger your function in that code block. – Rex Jun 06 '16 at 13:39
  • @HimanshuRaval i have mentioned this in my question that this will fire only after the close event, – Jiju John Jun 06 '16 at 13:48
  • check this question http://stackoverflow.com/questions/22221637/prevent-bootstrap-3-modal-from-closing-when-the-form-has-changes – tmg Jun 06 '16 at 13:58

1 Answers1

1

Use the hide.bs.modal event..

$('#myModal').on('hide.bs.modal', function (e) {
    //do something..
})

Example: http://www.codeply.com/go/wTys5mP4nw

Zim
  • 329,487
  • 83
  • 671
  • 600
  • I have mentioned in my question that we cannot handle here because it will fire only after closing the popup – Jiju John Jun 06 '16 at 13:52
  • This is the `hide` not `hidden` event. It will allow you to conditionally prevent closing. – Zim Jun 06 '16 at 13:54