does not work initialization modal
<div id="data_modal" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<div class="row">
<div class="col l12">
A bunch of text
</div>
</div>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat" id="save_frame">Сохранить</a>
</div>
</div>
<script type="text/javascript">
// заполняем и открываем модалочку
function _show_data_modal(_in){
var _elem = $('#data_modal');
var modal = M.Modal.getInstance(_elem);
// _elem.children('.modal-content').html('<h4>' + _in['title'] + '</h4>')
_elem.children('.modal-content').html(_in['content']);
modal.open();
}
</script>
===error
Uncaught TypeError: Cannot read property 'open' of undefined at _show_data_modal (lm=doc_edit&did=1:183) at eval (eval at success (scripts.js?v1522782874:20),
:1:1) at Object.success (scripts.js?v1522782874:20) at i (jquery-3.2.1.min.js:2) at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2) at A (jquery-3.2.1.min.js:4) at XMLHttpRequest. (jquery-3.2.1.min.js:4)
You have to call getInstance on the DOM Element not the jQuery wrapper on the element.
I decided it was easier just added
$(document).ready(function(){
$('#data_modal').modal();
});
we have same issue Modal
@socareta You didn't initialize the modal
var elem= document.querySelector('.modal'); var instance = M.Modal.init(elem, ''); M.Modal.getInstance(instance).open(); finally modal working with same error
https://codepen.io/Dogfalo/pen/xYXwoe
thank you so much, we have been tried using single html and working. but we use vue js. still have same error.
https://vuejs.org/v2/api/#mounted
great..now working...thanks
@socareta How did you solve it? The link provided by Dogfalo didn't really help me understand. Im trying to create an instance so I can call 'instance.close();' when button pressed in modal.
@jullemeister i am try use var elem= document.querySelector('.modal'); var instance = M.Modal.init(elem); onclick="instance .open()"
@Dogfalo
I tried this
console.log(M.Modal.getInstance(document.getElementById('loginModal')));
but I got undefined
@Dogfalo Nevermind I didn't put it in the DOMContentLoaded event listener
You can use this
Get element by ID
var elems = document.getElementById('idDivModal');
The next method is OPTIONAL
With this method you can reconfigure your DIV MODAL and you can add more options
var instances = M.Modal.init(elems, {
opacity: 0.5
});
New instance
var instance = M.Modal.getInstance(elems);
instance.open(); // instance with methods
I have still the same error... I can only use this in the jQuery ready method...
$(".modal").modal();
var modal = M.Modal.getInstance($(".modal"));
modal.open();