Search code examples
javascriptjquerycssmaterialize

Materialize bootstrap not being triggered


I have this code that when a user successfully added a new user it would trigger a modal. I have used materialize and the modal is not triggered. Here is part of my code:

<div id="thisismymodal" class="modal">
    <div class="modal-content">
        <h4>Modal Header</h4>
        <p>A bunch of text</p>
    </div>
    <div class="modal-footer">
        <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
    </div>
</div>

@if( Session::has('uadded') )
{{ Session::forget('uadded') }}
<script>    
    alert("well hello there!");
    $(document).ready(function()
    {
        $('#thisismymodal').leanModal();
        $('#thisismymodal').openModal();
    });
</script>

@endif

Only the alert is being triggered and not the modal. Any ideas on what I am doing wrong with my code?


Solution

  • For opening the modal by some event, you dont need $('#thisismymodal').leanmodal() as that is only for triggering on button click. As i can see, your modal should fire up programatically, so only $('#thisismymodal').openModal(); is needed.

    I'm assuming you are using php to add a user to the database. Do you have an 'if' condition which checks if the data has been written to the database successfully or not?

    You can fire up your script inside that 'if' statement if the data is successfully written.