Pass values from button to modal in Fancybox 3

193 views Asked by At

I have done the following with Bootstrap for passing data from button to modal which is working fine.

button:

<button type="button" class="btn btn-sm btn-info" data-toggle="modal"
    data-target="#viewSpaceModal"
    data-space_id="<?php  echo $space->ID; ?>"
    data-name="<?php echo $space->space_name; ?>"
    data-category="<?php echo $space->category; ?>"
    data-products='<?php
        if ($flag)
            echo json_encode($simple_product);
        ?>'
    >view space </button>

Getting values from button to bootstrap modal.

$("#viewSpaceModal").on("show.bs.modal", function (event) {

    var button = $(event.relatedTarget);
    var space_id = button.data("space_id");
    var name = button.data("name");
    var category = button.data("category");
    var products = button.data("products");
});

This is working fine. However, I am unable to achieve the same in Fancybox. I have tried the following:

Edit: I passed instance and slide as a parameter as in docs. How to extract the value?

$(".view-modal").fancybox({
    afterShow: function (instance, slide) {
        console.log(instance);
    },
});

This always return undefined. Any leads would be greatly appreciated.

0

There are 0 answers