Materialize: leanModal() - complete and ready callbacks are not executed

Created on 12 Aug 2016  路  7Comments  路  Source: Dogfalo/materialize

Here is the code to initialize Modal (on element ID):

$('#modal_confirm').leanModal({
        dismissible: false,
        out_duration: 200,
        complete: function() { console.log('closed'); },
        ready: function() { console.log('open'); }
    });

The modal itself:

<div id="modal_confirm" class="modal">
    <div class="modal-content" id="modal_confirm_content"></div>
    <div class="modal-footer">
        <a id="modal_confirm_action_yes" href="#" class="modal-action modal-close waves-effect waves-green btn green">Yes</a>
        <a href="#" class="modal-action modal-close waves-effect waves-red btn red">No</a>
    </div>
</div>

The modal is opened using openModal() function, since it also automatically fills down contents and assigns additional callback function to "yes" button - here is the function:

function showConfirmation(confirmText, positiveCallbackFunction) {
    $('#modal_confirm_content').html(confirmText);
    $('#modal_confirm').openModal();
    $('#modal_confirm_action_yes').on('click', function() {
        positiveCallbackFunction();
    });
}

Generally as it is now the "closed" or "open" texts never appears on console.
The version of Materialize used is 0.97.7 pulled from cdnjs.

Most helpful comment

Yes currently there are a lot of problems with our modal plugin. Currently using the openModal method does not use any of the options you defined. For a temporary fix you can store your options in a variable and pass that in to both .leanModal(options) and .openModal(options)

I'm currently working on rewriting the modal plugin to look similar to our other plugins where you would do things like .leanModal('open') instead of calling openModal

All 7 comments

Yes currently there are a lot of problems with our modal plugin. Currently using the openModal method does not use any of the options you defined. For a temporary fix you can store your options in a variable and pass that in to both .leanModal(options) and .openModal(options)

I'm currently working on rewriting the modal plugin to look similar to our other plugins where you would do things like .leanModal('open') instead of calling openModal

How are we doing with this? Will there be a fix coming anytime soon?

I just noticed this as well.
The modal jQuery interface needs to be changed. Currently, it is not possible to bind the ready and complete events to a modal, if it doesn't have a trigger and is just triggered via. JavaScript.
IMO, the leanModal() method should be called on the modal itself, since the trigger is optional and this makes more sense.

I've made a PR that rewrites a lot of modal. It's a pretty big change so I'm not merging yet until its fully tested. I would appreciate it a lot if you guys could check it out and let me know if it works well!

3511

Judging by the code, it looks just like I wanted it to be. Will take a look at it when I have time, but it definitely looks like the way forward and looks very promising.

I just noticed another problem with the old method, however very minor. When the browser is resized while a modal is open, the body has a fixed width and doesn't resize. Is this fixed in the new proposal?

Even on .99 .modal('open') does not trigger ready or complete (or creates a new modal, replacing the old one, I can't tell). You have to trigger the button or elements that correspond.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Robouste picture Robouste  路  3Comments

bradley-varol picture bradley-varol  路  3Comments

cope picture cope  路  3Comments

ReiiYuki picture ReiiYuki  路  3Comments

heshamelmasry77 picture heshamelmasry77  路  3Comments