I am trying to get a confirm box to pop up ONLY if a user has made change to the form inside the magnific popup that shows it's content in an iframe.
<a href="#" class="opener-class" data-mfp-src="/whatever.asp" data-lightbox="iframe" data-plugin-options='{"type":"iframe"}'>
code:
$('.opener-class').magnificPopup({
type:'iframe',
change: function() {
$.magnificPopup.instance.close = function () {
if (!confirm("Are you sure?")) {
return;
}
$.magnificPopup.proto.close.call(this);
};
}
});
Change does not seem to work. I tried to bind the form inside open: like we do on the rest of our site, but that did not work either.
$(':input', document.myForm).bind("change", function() {
//confirm here
}
);
HTML for Form Sample on the page in whatever.asp that gets submitted - if anything is changed in that textbox, I want the confirm close to appear:
<form class="validate" action="/whatever.asp" method="post">
<label>Notes</label>
<textarea class="form-control input-sm required" name="Notes" id="Notes" rows="3"></textarea>
</form>
I think the issue is that the code is on the parent page and then opens a magnific popup content in an iFrame.
Any help would be appreciated!
I have been playing around with all these options and none seem to work. Here's the issue - the "change" is not firing for a form. "change" is firing for the popup, but if I wrap the check for a change in a form item with console logs, they are fine, but the cosole log inside the form change does not fire. The issue here has to be with accessing the form items since they are in an iframe!!! So, I ended up just not using the default close button, using modal=true, and created my own close button inside the iframe that I programmatically control myself onclick on the button class and parent.$.magnificPopup.close(); from inside the iframe - works like a charm.