I want to prevent magnificPopup dialog from displaying when I click a button and when no checkboxes are checked.
Here is what I have tried already:
$('[id$=DeleteSelectedItems]').click(function (evt) {
if ($("#datatable :checked").length == 0) {
evt.preventDefault();
$.magnificPopup.remove(); //prevent dialog popup if no checkbox selected
}
});
The above code is doing what I want except $.magnificPopup.remove(); is not a valid function.
So although $.magnificPopup.remove(); prevents the popup from showing, (because it breaks the JavaScript!) it is not a valid function and I get an error in my console when testing this. I have tried $.magnificPopup.destroy(); and $.magnificPopup.stop(); but they are also not valid.
Many thanks for any help you can provide with this!
Thanks for your replies. I ended up using $.magnificPopup.close(); but, importantly, I put my code after the initialisation of magnific popup. Previously, I had it before the initialisation. Stupid mistake! So my working jQuery is:
// initialise magnific popup
$('.open-popup-link').magnificPopup({
type: 'inline',
midClick: true
});
//don't fire the delete button if no checkbox selected in table with id of datatable
$('[id$=DeleteSelectedItems]').click(function (evt) {
if ($("#datatable :checked").length == 0) {
evt.preventDefault();
$.magnificPopup.close(); //prevent dialog popup if no checkbox selected
}
});
Many thanks for pointing me in the right direction! : )